Commit graph

32 commits

Author SHA1 Message Date
Vas Sudanagunta b93417aa1d Unify page lookups
This commit unifies the core internal page index for all page kinds.

This enables the `ref` and `relref` shortcodes to support all pages kinds, and adds a new page-relative  `.GetPage` method with simplified signature.

See #4147
See #4727
See #4728
See #4728
See #4726
See #4652
2018-07-18 00:07:20 +02:00
Bjørn Erik Pedersen dea71670c0
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.

This commit adds

* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.

This means that you can now do this in your templates (or shortcodes):

```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```

This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:

```
HUGO_BUILD_TAGS=extended mage install
```

Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.

The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:

```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```

The transformation funcs above have aliases, so it can be shortened to:

```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```

A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.

Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test

New functions to create `Resource` objects:

* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.

New `Resource` transformation funcs:

* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.

Fixes #4381
Fixes #4903
Fixes #4858
2018-07-06 11:46:12 +02:00
Bjørn Erik Pedersen eb42774e58
Add support for a content dir set per language
A sample config:

```toml
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true

[Languages]
[Languages.en]
weight = 10
title = "In English"
languageName = "English"
contentDir = "content/english"

[Languages.nn]
weight = 20
title = "På Norsk"
languageName = "Norsk"
contentDir = "content/norwegian"
```

The value of `contentDir` can be any valid path, even absolute path references. The only restriction is that the content dirs cannot overlap.

The content files will be assigned a language by

1. The placement: `content/norwegian/post/my-post.md` will be read as Norwegian content.
2. The filename: `content/english/post/my-post.nn.md` will be read as Norwegian even if it lives in the English content folder.

The content directories will be merged into a big virtual filesystem with one simple rule: The most specific language file will win.
This means that if both `content/norwegian/post/my-post.md` and `content/english/post/my-post.nn.md` exists, they will be considered duplicates and the version inside `content/norwegian` will win.

Note that translations will be automatically assigned by Hugo by the content file's relative placement, so `content/norwegian/post/my-post.md` will be a translation of `content/english/post/my-post.md`.

If this does not work for you, you can connect the translations together by setting a `translationKey` in the content files' front matter.

Fixes #4523
Fixes #4552
Fixes #4553
2018-04-02 08:06:21 +02:00
Bjørn Erik Pedersen e39797fa72
hugolib: Avoid scanning entire site to find the home
See #4447
2018-02-25 10:50:44 +01:00
Bjørn Erik Pedersen ae5a45be6f
hugolib: Remove unused code 2018-01-25 17:14:03 +01:00
Bjørn Erik Pedersen 3446fe9b89
hugolib: Add the last lookup variant for the GetPage index
Now, even for nun-bundles it is possible to do lookup without path or extension.

So, given `blog/my-blog-post.en.md` these lookups will succeed:

* `blog/my-blog-post.en.md`
* `blog/my-blog-post`
* `my-blog-post.en.md`
* `my-blog-post`

See #4312
See https://github.com/gohugoio/hugoDocs/issues/307
2018-01-24 13:36:06 +01:00
Bjørn Erik Pedersen 517b6b6238 hugolib: Simplify bundle lookup via .Site.GetPage, ref, relref
Given a bundle in `blog/my-bundle/index.en.md` all of these will now worK:

* `blog/my-bundle/index.en.md`
* `blog/my-bundle/index`
* `blog/my-bundle`
* `my-bundle`

The last one is potentially ambigous.

Fixes #4312
2018-01-24 10:05:20 +01:00
Bjørn Erik Pedersen 0432c64dd2 Add headless bundle support
This commit adds  support for `headless bundles` for the `index` bundle type.

So:

```toml
headless = true
```

In front matter means that

* It will have no `Permalink` and no rendered HTML in /public
* It will not be part of `.Site.RegularPages` etc.

But you can get it by:

* `.Site.GetPage ...`

The use cases are many:

* Shared media galleries
* Reusable page content "snippets"
* ...

Fixes #4311
2018-01-24 09:00:21 +01:00
Bjørn Erik Pedersen 9409bc0f79 Improve .Site.GetPage for regular translated pages
You can still use the full path with extensions, but to get the current language version:

* If the content file lives in `/content/blog/mypost.en.md`
* Use `.Site.GetPage "page" "blog/mypost"`

Fixes #4285
2018-01-17 22:27:25 +01:00
Bjørn Erik Pedersen 3cdf19e9b7
Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.

Some hightlights include:

* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).

A site building  benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:

```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"

benchmark                                                                                                         old ns/op     new ns/op     delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      101785785     78067944      -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     185481057     149159919     -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      103149918     85679409      -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     203515478     169208775     -16.86%

benchmark                                                                                                         old allocs     new allocs     delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      532464         391539         -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     1056549        772702         -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      555974         406630         -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     1086545        789922         -27.30%

benchmark                                                                                                         old bytes     new bytes     delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      53243246      43598155      -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     105811617     86087116      -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4      54558852      44545097      -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4     106903858     86978413      -18.64%
```

Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-12-27 18:44:47 +01:00
Bjørn Erik Pedersen a9be687b81
hugolib: Pre-allocate some slices 2017-11-11 09:39:43 +01:00
Bjørn Erik Pedersen d8717cd4c7 all: Update import paths to gohugoio/hugo 2017-06-13 18:42:45 +02:00
Bjørn Erik Pedersen 55dd533bf7 hugolib: Unexport some internal methods 2017-06-08 22:33:18 +02:00
Bjørn Erik Pedersen fe901b8119 hugolib, commands: Improve live-reload on directory structure changes
This issue is more visible now that we support nested sections.

This commit makes operations like pasting new content folders or deleting content folders during server watch just work.

Fixes #3570
2017-06-08 20:14:28 +02:00
Bjørn Erik Pedersen b39689393c hugolib: Enable nested sections
Fixes #465
2017-06-08 11:21:34 +02:00
Bjørn Erik Pedersen 612f6e3afe hugolib: Fix ref/relref issue with duplicate base filenames
This commit also makes that function 80x faster.

Fixes #2507
2017-05-26 10:42:45 +03:00
Bjørn Erik Pedersen 50d11138f3 hugolib: Add a cache to GetPage
Looks to be slightly slower with the low number of section pages, but the 1000 regular pages seem to add value.

```
benchmark                     old ns/op     new ns/op     delta
BenchmarkGetPage-4            97.7          145           +48.41%
BenchmarkGetPageRegular-4     7933          161           -97.97%

benchmark                     old allocs     new allocs     delta
BenchmarkGetPage-4            0              0              +0.00%
BenchmarkGetPageRegular-4     0              0              +0.00%

benchmark                     old bytes     new bytes     delta
BenchmarkGetPage-4            0             0             +0.00%
BenchmarkGetPageRegular-4     0             0             +0.00%
```
2017-05-26 10:42:45 +03:00
Bjørn Erik Pedersen e0c2e79820 hugolib: Support regular pages in .Site.GetPage
Fixes #2844
2017-05-26 10:42:45 +03:00
Bjørn Erik Pedersen fbb78b89df hugolib: Speed up GetPage
When we know to look into the index pages collection, do that:

```
benchmark              old ns/op     new ns/op     delta
BenchmarkGetPage-4     51483         7072          -86.26%

benchmark              old allocs     new allocs     delta
BenchmarkGetPage-4     71             71             +0.00%

benchmark              old bytes     new bytes     delta
BenchmarkGetPage-4     2648          2648          +0.00%
```

This commit also returns an error if .Site.GetPage is called with the regular Page Kind, as that is currently not supported.

Fixes #3503
2017-05-23 15:18:26 +03:00
Bjørn Erik Pedersen 2f2ea42c09 hugolib: Fix reloading corner cases for shortcodes
This commit fixes two different, but related issues:

1) Live-reload when a new shortcode was defined in the content file before the shortcode itself was created.
2) Live-reload when a newly defined shortcode changed its "inner content" status.

This commit also improves the shortcode related error messages to include the full path to the content file in question.

Fixes #3156
2017-03-11 20:21:06 +01:00
bogem faba90ab96 helpers: Fix misspells 2017-02-04 22:28:36 +01:00
Bjørn Erik Pedersen a843d5d3bb node to page: Final TODO-fixes
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 62e9e7e6ba node to page: Misc. TODO-fixes
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen c8d3124dde node to page: Remove Node
And misc. TODO-fixes

Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 9347084d61 node to page: Make Kind a string
Having a custom string type isn't worth it when it doesn't work
with `where`, `eq` etc.

Fixes #2689
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 9fba2a30a9 node to page: Rename PageType to Kind
And embed that on Page.

Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 96f71141bd node to page: Export GetPage to the templates
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen c80308e6b3 node to page: Add Pages to Page
As an alias to .Data.Pages for home page etc.

Also renamte NodeType to PageType and make it a string so it can be used in `where`.

Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 063b78d2ec node to page: Make Nodes into Pages
* `.Site.Pages` now contains all page types, including sections etc.
* `.Data.Pages` will also contain "node type" pages where relevant.

Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen d3d3863c05 node to page: Add all nodes to sitemap
Updates #2297
Fixes #1303
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen ec2d502b4f node to page: Handle translations
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen 698b994f71 node to page: Fix the page collections
Updates #2297
2016-11-22 09:57:03 +01:00