Commit graph

54 commits

Author SHA1 Message Date
Bjørn Erik Pedersen ec2d502b4f node to page: Handle translations
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 4b4ab47553 hugolib: Fix page sorting when weight is zero
Fixes #2673
2016-11-06 15:39:33 +01:00
Albert Nigmatzianov f21e2f25c9 all: Unify case of config variable names
All config variables starts with low-case and uses camelCase.

If there is abbreviation at the beginning of the name, the whole
abbreviation will be written in low-case.
If there is abbreviation at the end of the name, the
whole abbreviation will be written in upper-case.
For example, rssURI.
2016-10-24 20:56:00 +02:00
Bjørn Erik Pedersen a07293cf97 Create a Node map to get proper node translations
In a multi-language setup, before this commit the Node's Translations() method
would return some "dummy nodes" that would point to the correct page (Permalink),
but would not be the same as the node it points to -- it would not have the translated
title etc.

The node creation is, however, so mingled with rendering, whihc is too early to have any global state,
so the nodes has to be split in a prepare and a render phase. This commits does that with as small
a change as possible. This implementation is a temp solution until we fix #2297.

Updates #2309
2016-09-06 18:32:19 +03:00
Bjørn Erik Pedersen 54141f71dd Improve language handling in URLs
The current "rendering language" is needed outside of Site. This commit moves the Language type to the helpers package, and then used to get correct correct language configuration in the markdownify template func.
This commit also adds two new template funcs: relLangURL and absLangURL.

See #2309
2016-09-06 18:32:18 +03:00
Bjørn Erik Pedersen 708bc78770 Optimize the multilanguage build process
Work In Progress!

This commit makes a rework of the build and rebuild process to better suit a multi-site setup.

This also includes a complete overhaul of the site tests. Previous these were a messy mix that
were testing just small parts of the build chain, some of it testing code-paths not even used in
"real life". Now all tests that depends on a built site follows the same and real production code path.

See #2309
Closes #2211
Closes #477
Closes #1744
2016-09-06 18:32:16 +03:00
Bjørn Erik Pedersen 3a02807970 Add Translations and AllTranslations to Node
This commit also consolidates URLs on Node vs Page, so now .Permalink should be interoperable.

Note that this implementations should be fairly short-livded, waiting for #2297, but the API should be stable.
2016-09-06 18:32:16 +03:00
Bjørn Erik Pedersen 75dd596e6c Introduce HugoSites type
And a Hugo global variable which contains the site under build.

This is really needed to get some level of control of the "multiple languages" in play.

There are still work related to this scattered around, but that will come.

With this commit, the multilingual feature is starting to work.
2016-09-06 18:32:16 +03:00
Alexandre Bourget ec33732fbe Add multilingual support in Hugo
Implements:
* support to render:
  * content/post/whatever.en.md to /en/2015/12/22/whatever/index.html
  * content/post/whatever.fr.md to /fr/2015/12/22/whatever/index.html
* gets enabled when `Multilingual:` is specified in config.
* support having language switchers in templates, that know
  where the translated page is (with .Page.Translations)
  (when you're on /en/about/, you can have a "Francais" link pointing to
   /fr/a-propos/)
  * all translations are in the `.Page.Translations` map, including the current one.
* easily tweak themes to support Multilingual mode
* renders in a single swift, no need for two config files.

Adds a couple of variables useful for multilingual sites

Adds documentation (content/multilingual.md)

Added language prefixing for all URL generation/permalinking see in the
code base.

Implements i18n. Leverages the great github.com/nicksnyder/go-i18n lib.. thanks Nick.
* Adds "i18n" and "T" template functions..
2016-09-06 18:32:15 +03:00
Bjørn Erik Pedersen 20c4311df4 Switch to a more up to date TOML library
Fixes #2089
2016-08-20 20:33:06 +01:00
Cameron Moore 715d4425ad hugolib: Use named keys in composite literals
Make `go vet` great again
2016-08-19 12:22:19 +01:00
Bjørn Erik Pedersen 608cfe62cf Remove kr/pretty dependency
Fixes #2124
See https://github.com/kr/text/issues/6
2016-05-08 13:16:16 +02:00
Bjørn Erik Pedersen c0cf1a7e37 Fix section menus for lazy blogger
IsMenuCurrent was always returning false for the top level entries.

Fixes #2065
2016-04-10 13:49:32 +02:00
Bjørn Erik Pedersen 1c3c148b38 hugolib: Un-export internal Site-methods
These are obviously internal and for the most part undocumented, creating lots of GoLint warnings.

See #1160
See #2014
2016-04-08 17:55:23 +02:00
Bjørn Erik Pedersen 4f66f790b1 Add readFile template func
This also includes a refactor of the hugofs package and its usage.

The motivation for that is:

The Afero filesystems are brilliant. Hugo's way of adding a dozen of global variables for the different filesystems was a mistake. In readFile (and also in some other places in Hugo today) we need a way to restrict the access inside the working dir. We could use ioutil.ReadFile and implement the path checking, checking the base path and the dots ("..") etc. But it is obviously better to use an Afero BasePathFs combined witha ReadOnlyFs. We could create a use-once-filesystem and handle the initialization ourselves, but since this is also useful to others and the initialization depends on some other global state (which would mean to create a new file system on every invocation), we might as well do it properly and encapsulate the predefined set of filesystems. This change also leads the way, if needed, to encapsulate the file systems in a struct, making it possible to have several file system sets in action at once (parallel multilanguage site building? With Moore's law and all...)

Fixes #1551
2016-03-31 21:24:18 +02:00
Bjørn Erik Pedersen dc7d8a9eac Spring cleaning of the menu code 2016-03-23 00:29:39 +01:00
Bjørn Erik Pedersen df92fc31ca hugolib: Fix Java-styled all-caps consts 2016-03-22 23:59:07 +01:00
Bjørn Erik Pedersen dea185aa9b hugolib: Remove unused code 2016-03-14 15:41:03 +01:00
Bjørn Erik Pedersen 924028a9be Fix for page in multiple menus
Fixes #1934
2016-03-10 10:31:12 +01:00
Bjørn Erik Pedersen 0f6c8439b9 Add missing menu tests 2016-02-07 13:43:42 +01:00
Bjørn Erik Pedersen 75044c199f Add menu sort tests 2016-02-07 12:34:43 +01:00
Bjørn Erik Pedersen 7c3dceeaed Fix buggy Menu.Limit() 2016-02-06 22:53:59 +01:00
Bjørn Erik Pedersen 78f9bf2444 Add one more menu test
See #1774
2016-01-14 17:30:05 +01:00
Bjørn Erik Pedersen ab70e6f52f Add menu test for external URL
See #1774
2016-01-14 15:14:21 +01:00
Anthony Fok 8509727fe8 Add copyright header to that source files that don’t have one.
See #1646
2015-12-10 15:19:38 -07:00
gunnaraasen d35d82060f Remove transformation of menu URLs
Fixes #1239
2015-12-06 15:25:23 +01:00
Valere JEANTET 2c22a8b79a fix TestHomeNodeMenu test
Signed-off-by: Valere JEANTET <valere.jeantet@gmail.com>
2015-07-14 21:31:47 +02:00
Bjørn Erik Pedersen d4b6f9aca3 Fix map-order dependent menu tests
Fixes #1222
2015-06-21 23:36:58 +02:00
Bjørn Erik Pedersen c507229191 Print URL when failing menu test
See #1222
2015-06-21 23:09:39 +02:00
Bjørn Erik Pedersen ae4f72b091 Comment out mystery test
Fails on Travis in Go 1.3 + 1.5.

Will have to look into that one.
2015-06-21 22:28:50 +02:00
bep be6cf6a9c6 Revert "Add some debug to failing menu test"
This reverts commit becc627e1e.
2015-06-12 22:49:49 +02:00
bep becc627e1e Add some debug to failing menu test 2015-06-11 22:49:07 +02:00
bep bed8197de5 Move Viper reset to correct level in menu tests 2015-06-11 22:41:17 +02:00
bep beda46d289 Reset Viper for every duplicate menu test iteration 2015-06-11 21:22:29 +02:00
bep be7404e337 Support Fish and Chips section
Section names are also used as the title of the list pages, but naming section folders as `Fish and Chips` and similar didn't work very well.

This commit fixes that.

This commit also changes the title casing of the section titles. Some may argue that this is a breaking change, but the old behaviour was also pretty broken,
even for languages that use title capitalizations, as it didn't follow any particular style guide, `fish and chips` became `Fish And Chips` etc.

Now it just turns the first letter into upper case, so `Fish and Chips` will be left as `Fish and Chips`.

People wanting the good old behaviour can use the `title` template func.

Fixes #1176
2015-05-28 23:05:17 +02:00
spf13 a584ff207b Stop Viper from leaking across many of the tests (now tests pass regardless of order tested) 2015-05-20 02:21:21 -04:00
bep be325a3088 Fix IsMenuCurrent for SectionPagesMenu
Pretty sure it has worked at some point, but that PR probably has been rebased to pieces.

This refactors the fix by @dannys42 into a method, as this URL fix is applied several places.

Fixes #1114
2015-05-09 20:53:58 +02:00
bep d4acacd4f5 Section menu for the lazy blogger
The current menu system works great, but is too much work if all you want is a simple menu with the sections as menu items, and having these menu items connected to the pages in a way that enables setting the correct menu item as active for both the section lists and the pages itself.

This commit adds a new option `SectionPagesMenu' which, if set, will create a new menu with that name with all the sections as menu items. The pages in the sections will behave as "shadow members" of these section items as `blogpage.HasMenuCurrent "sectionmenu" $sectionmenuitem` will return true.

If a menu item with the same `identifier` is defined in site config, *that* item will take precedence.
2015-05-08 21:28:19 -04:00
bep bed053071e Remove unused types Shortcode and ShortcodeFunc 2015-04-18 00:31:56 +02:00
Anthony Fok 8b8fb417ae More initialism corrections (golint)
Thanks to @bep's new, brilliant helpers.Deprecated() function,
the following functions or variables are transitioned to their
new names, preserving backward compatibility for v0.14
and warning the user of upcoming obsolescence in v0.15:

 * .Url → .URL (for node, menu and paginator)
 * .Site.BaseUrl → .Site.BaseURL
 * .Site.Indexes → .Site.Taxonomies
 * .Site.Recent → .Site.Pages
 * getJson → getJSON
 * getCsv → getCSV
 * safeHtml → safeHTML
 * safeCss → safeCSS
 * safeUrl → safeURL

Also fix related initialisms in strings and comments.

Continued effort in fixing #959.
2015-03-18 11:30:37 +01:00
Anthony Fok 67df33f500 Correct initialisms as suggested by golint
First step to use initialisms that golint suggests,
for example:

    Line 116: func GetHtmlRenderer should be GetHTMLRenderer

as see on http://goreportcard.com/report/spf13/hugo

Thanks to @bep for the idea!

Note that command-line flags (cobra and pflag)
as well as struct fields like .BaseUrl and .Url
that are used in Go HTML templates need more work
to maintain backward-compatibility, and thus
are NOT yet dealt with in this commit.

First step in fixing #959.
2015-03-11 21:55:00 +01:00
bep 5759007874 menu: make receiver name on Page methods consistent
Apply some Golint rules on Menu, esp. making the method receiver names consistent.
2015-03-07 12:52:29 +01:00
bep fa71f6c11e Make # survice Url cleaning
To enable anchors in Urls.

Fixes #888
2015-02-10 19:14:19 +01:00
Jonathan Anderson e72ce89aaf Move s.prepUrl() before prepending BaseUrl.
When we have an absolute menu url specified in the config file
(e.g., `menu: { main: { name: "News", url: "/news" } }`),
its menu entry is generated by prefixing it with the BaseUrl.
The result is then run through prepUrl(), which uses helpers.Urlize to
convert urls such as 'My First Link' to 'my-first-link'.

The behaviour is backwards: we do not want to run helpers.Urlize on the
BaseUrl, only on the absolute component. Currently, a BaseUrl such as
'http://my.edu/ENG101' will be converted to 'http://my.edu/eng101',
resulting in broken links in all of my menus.

This commit switches the URL prep and BaseUrl prepending actions around. I
would argue that these URLs shouldn't be run through prepUrl anyway
because the site developer has specified them explicitly in a config file
and might be surprised for, e.g., URLs to change case, but that's another
commit for another time.
2015-01-26 01:03:18 +01:00
bep 1b42dc572a Fix RelPermalink() and Urls in menus vs canonifyUrls
canonifyUrls=true, RelPermalink and baseUrl with sub-path did not work.

This fixes that by adding a check for canonifyUrl=trues=true in RelPermalink().

So given

- baseUrl "http://somehost.com/sub/"
- the path "some-path/file.html"

For canonifyUrls=false RelPermalink() returns "/sub/some-path/file.html"
For canonifyUrls=true RelPermalink() returns "/some-path/file.html"

In the last case, the Url will be made absolute and clickable in a later step.

This commit also makes the menu urls defined in site config releative. To make them work with canonifying of urls, the context root is prepended if canonifying is turned off.

Fixes #519
Fixes #711
2015-01-23 14:13:00 +01:00
bep 01ec44a6b4 Add menu tests for pages with both Yaml and Toml front matter
See #817
2015-01-22 17:23:01 +01:00
bep 076a475d16 Revert "Temporarily disable failing menu test"
This reverts commit e4a22255cc.
2015-01-01 23:40:14 +01:00
bep bb37698226 Fix unicode menu URLs
Menu urls like /categories/новости-проекта would turn into /categories/d0bdd0bed0b2d0bed181d182d0b8-d0bfd180d0bed0b5d0bad182d0b0, which is illegal, while the directory under the categories/ is created with the original name. It results in 404 not found error.

This commit fixes that by make sure that SanitizeUrl() is called last.

Fixes #719
2014-12-26 13:30:46 +01:00
bep e4a22255cc Temporarily disable failing menu test 2014-12-26 13:14:06 +01:00
bep 9b04c27998 Revert "Make Urls in menus respect CanonifyUrls"
This reverts commit 3ccb397902.
2014-12-11 05:33:40 +01:00