My goal is to build a multilingual site using hugo. For this I would like to:
not touch the theme file
have a config file which defines the overall structure for all languages (config.toml)
have a "string" file for all languages
So for example, I would have a config.toml file like this:
[params.navigation]
brand = "out-website"
[params.navigation.links]
about = $ABOUT_NAME
services = $SERVICES_NAME
team = $TEAM_NAME
impressum = $IMPRESSUM_NAME
a english language file:
ABOUT_NAME=About
SERVICES_NAME=Services
TEAM_NAME=Team
IMPRESSUM_NAME=Impressum
and a german language file like this:
ABOUT_NAME=Über uns
SERVICES_NAME=Dienste
TEAM_NAME=Mitarbeiter
IMPRESSUM_NAME=Impressum
And then I want to compile the project for english, I do something along the line of:
hugo --theme=... --config=config.toml --config=english.toml
and german:
hugo --theme=... --config=config.toml --config=german.toml
Or in same similar way.
For this I need to use variables in the config.toml that are defined in english.toml or german.toml
My google search so far say, that I cannot use variables in toml.
So is there a different approach with which I could achieve this?
Your approach with variables is not optimal, use the tutorial below.
Multilingual sites are coming as a feature on Hugo 0.16, but I managed to build a multilingual site on current Hugo using this tutorial and some hacks.
The tutorial above requires to "have a separate domain name for each language". I managed to bypass that and to have to sites, one at root (EN), and one in the folder (/LT/).
Here are the steps I used.
Set up reliable build runner, you can use Grunt/Gulp, but I used npm scripts. I hacked npm-build-boilerplate and outsourced rendering from Hugo. Hugo is used only to generate files. This is important, because 1) we will be generating two sites; 2) hacks will require operations on folders, what is easy on npm (I'm not proficient on building custom Grunt/Gulp scripts).
Set up config_en.toml and config_de.toml in root folder as per tutorial.
Here's excerpt from my config_en.toml:
contentdir = "content/en"
publishdir = "public"
Here's excerpt from my config_lt.toml (change it to DE in your case):
contentdir = "content/lt"
publishdir = "public/lt"
Basically, I want my website.com to show EN version, and website.com/lt/ to show LT version. This deviates from tutorial and will require hacks.
Set up translations in /data folder as per tutorial.
Bonus: set up snippet on Dash:
{{ ( index $.Site.Data.translations $.Site.Params.locale ).#cursor }}
Whenever I type "trn", I get the above, what's left is to paste the key from translations file and I get the value in correct language.
Hack part. The blog posts will work fine on /lt/, but not static pages (landing pages). I use this instruction.
Basically, every static page, for example content/lt/duk.md will have slug set:
slug: "lt/duk"
But this slug will result in double URL path, for example lt/lt/duk.
I restore this using my npm scripts task using rsync and manual command to delete redundant folder:
"restorefolders": "rsync -a public/lt/lt/ public/lt/ && rm -rf public/lt/lt/",
Related
I am using hugo (https://gohugo.io/) and trying to make an external link in the menu (docsy theme).
I changed the _index.md to:
---
title: "Documentation"
linkTitle: "Documentation"
url: "https://www.myurl.com"
weight: 20
menu:
main:
weight: 20
---
However hugo reports:
Rebuild failed: URLs with protocol (http*) not supported
Could anyone advise of how to create an external URL link directly on the menu?
Thanks, Gregor
Keep in mind that "url" is a predefined front matter variable that is meant to be used for defining the full path to the content page from the site root. If you want to add an external link in your front matter, I'd recommend giving the variable a different name, e.g. "external_url".
I just added something like this:
[[menu.main]]
name = "GitHub"
weight = 50
url = "https://github.com/google/docsy/"
To the config.toml file.
I found this solution for the docsy theme here: https://www.docsy.dev/docs/adding-content/navigation/
Hope this helps, Gregor
I am using bizreview as the theme for my Drupal 7 site. I am using the Feeds module to import thousands of records that are in CSV files into the site. I need to use a geofield to store the locations.
For this I created a field 'Coordinates' in my content type, made it a geofield and set the widget type to latitude/longitude. I can add the locations manually and they do show up in the map, but I just can't import the coordinates with Feeds.
This seems to be an ongoing issue with the geofield/feeds interface (see Drupal issue here). I had the same problem but applied the patch in comment #12 from the aforementioned link which worked.
One suggestion: If the current version of geofield is not the same as the one used in the patch, or if you are running WAMP without Cygwin, I would suggest applying the patch manually by following the directions here, making sure to save a safe backup file in the process. If you haven't worked with patches before, basically all that you (or the patch command) will do for this particular case is add the following lines of code after line 143 in the ./sites/all/modules/geofield/geofield.feeds.inc file (I am working with geofield version 7.x-2.3):
foreach ($field[LANGUAGE_NONE] as $delta => $value) {
if (!empty($value['lat']) && !empty($value['lon'])) {
// Build up geom data.
$field[LANGUAGE_NONE][$delta] = geofield_compute_values($value, 'latlon');
}
}
I got a "framework" created by us using AngularJS. It allows to build questionnaire system and it has many different parameters that control the behavior of framework.
Using this framework we've created 2 projects: projectA and projectB. The difference between these projects are the settings and assets (css, img, ...)
Both projects are stored on the same branch in git and only config file defines the project customization.
I can't think of the best way how these 2 projects can be easily deployed separately from the same code source using Gulp or something other.
Here are some ideas I got for the moment:
1. Have both settings files and images (e.g. logo_A.png and logo_B.png) in the code and choose appropriate during build using Gulp
2. Create folder customizations that will have 2 subfolders A and B with corresponding settings and assets
3. Create separate repository for each project installation scripts (not the code) and these scripts will do all the work
What is the best way in this case?
Finally, the easieast and most understandible solution was to create additional custom folder.
Assets
In addition to normal application files I got now custom folder with 2 subfolders: A and B each of them containing assets (css, img) that correspond only to concrete project.
In gulp I've used yargs module which allows to pass parameters. After reading project name from input I can looks inside custom folder to see if there are resources interesting for me (I've just added custom folder into the resources paths).
var customPath = './custom/' + app.name;
exports.paths = {
web: {
//Resources
styles: ['./app/**/*.css', './app/**/*.scss', customPath + '/**/*.css', customPath + '/**/*.scss'],
...
And the call to build task now looks like this: gulp build --name A.
Configuration
One more thing was done for configuration file of AngularJS that contains constants. I've used gulp-ng-config plugin which allows to build AngularJS configuration (constants) file on fly. In my flow, first I check if custom configuration file exists inside custom folder I use it, if no I'm using default one from application.
var getAppScripts = function() {
return $.eventStream.merge(
gulp.src(config.paths.web.scripts)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
//.pipe($.eslint())
.pipe($.eslint.format()),
getAppConfig())
.pipe($.angularFilesort());
};
var getAppConfig = function() {
var configFile = config.paths.web.custom + "/app.config.yaml";
if (fs.existsSync(configFile)) {
return gulp.src(configFile)
.pipe($.ngConfig(config.app.name, {
parser: 'yml',
createModule: false
}));
}
else {
return gulp.src(config.paths.web.config);
}
}
name = Lucas description = Drupal-thema gemaakt voor de kinderafdeling
AZ St-Lucas Gent. package = Core version = VERSION core = 7.x
stylesheets[all][] = style.css
scripts[] = scripts/lib/modernizr.js
settings[garland_width] = fluid
; Information added by drupal.org packaging script on 2013-02-20
version = "7.x" project = "drupal" datestamp = "1361393684"
It's possible that your JS file isn't at that location, meaning that Drupal will automatically avoid generating a 404 by omitting the call to the non-existent file.
You could also rely on the Modernizr Drupal module and it takes care of placement for you. It can also keep Modernizr up to date more easily by supplying you with a drush command to refresh the file, along with a nice API that allows for custom builds to be generated more conveniently. Check it out!
see the installation instructions to use modernizr http://drupal.org/project/modernizr
I'm using the CakePHP Plugin AssetCompress (v 0.7) which works fine, except that it doesn't cache any files in the directory. This is my asset_compress.ini setup:
[General]
writeCache = true
cacheConfig = false
alwaysEnableController = true
debug = false
[js]
timestamp = true
paths[] = WEBROOT/js/
cachePath = WEBROOT/cache_js/
[speedtest.min.js]
files[] = speedtest/speedtest.js
Additional notes:
I set debug to "0" in core.php
the cache_js folder is writeable (777)
also I'm using MemCache as a caching engine (not sure if this might cause the issue)
Has anybody experienced the same issue with the Asset Compress plugin?
Update: This is what I use for the CSS/Less part, works pretty well: https://github.com/Hyra/less
If I understand well this Github's wiki page you should change cacheConfig = false to cacheConfig = true to take advantage of MemCache.
You have to generate the files using the shell script. The files are not automatically generated.
https://github.com/markstory/asset_compress/wiki/Shell
To generate and store static assets defined in the asset_compress.ini config or through the AssetCompress helper on the fly. This is to save you having to manually run the console script everytime you change you css or js files.
This is what some will define as a "nasty" hack, I call it a working solution. It simply runs the console script via the php exec() method every time the AppController beforeFilter() runs and the debug level is greater than 0. So in production where your debug level should be 0, the exec() won't be run.
Add the following to your /app/Controller/AppController.php beforeFilter() function.
if(Configure::read('debug') > 0){
exec(APP.'Console'.DS.'cake -app '.APP.' AssetCompress.asset_compress build -f');
}
This is assuming that you can run the normal AssetCompress from the console (linux) or cmd prompt (windows)