Commit graph

680 commits

Author SHA1 Message Date
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 8aec5ee2dd hugolib: Some more unexports 2016-03-25 03:12:31 +01:00
Bjørn Erik Pedersen 6dbae7b671 Be explicit about the type in Scratch test
A puzzle, but it sometimes produces a int64 as it is now.
2016-03-24 19:57:26 +01:00
Bjørn Erik Pedersen d770130530 hugolib: Remove unused Tmpl on Page 2016-03-24 18:34:41 +01:00
Bjørn Erik Pedersen c846b051f3 Do not use defer for unlocking in Scratch
It is a fairly costly operation:

```
benchmark                 old ns/op     new ns/op     delta
BenchmarkScratchGet-4     109           31.6          -71.01%

benchmark                 old allocs     new allocs     delta
BenchmarkScratchGet-4     0              0              +0.00%

benchmark                 old bytes     new bytes     delta
BenchmarkScratchGet-4     0             0             +0.00%
´´´
2016-03-24 16:03:31 +01:00
Bjørn Erik Pedersen fa1a9653e5 hugolib: Taxonomy GoDoc cleanup 2016-03-24 16:01:25 +01:00
Bjørn Erik Pedersen b5bced1db4 Add a simple benchmark for Scratch 2016-03-24 15:05:40 +01:00
Bjørn Erik Pedersen 7c84e6b3e3 hugolib: Even more Golint fixes 2016-03-24 14:42:03 +01:00
Bjørn Erik Pedersen 3bbfd99176 hugolib: Apply Golint rules to rss_test.go 2016-03-24 14:20:00 +01:00
Bjørn Erik Pedersen b8bf01cdc6 hugolib: Add missing GoDoc in pagination.go 2016-03-24 14:18:47 +01:00
Bjørn Erik Pedersen c2c73c2bd2 hugolib: Some more GoLint fixes 2016-03-24 14:11:04 +01:00
Bjørn Erik Pedersen e467d23374 hugoblib: Clean up the time tests 2016-03-24 13:30:08 +01:00
Bjørn Erik Pedersen a6de8dfb42 hugolib: Some more Golint fixes 2016-03-23 17:17:54 +01:00
Bjørn Erik Pedersen dac34f9bfd hugolib: Fix spelling mistake 2016-03-23 17:12:47 +01:00
Bjørn Erik Pedersen c31fa378c7 hugolib: Add Godoc to pageSort 2016-03-23 17:11:29 +01:00
Bjørn Erik Pedersen 937592cb85 hugolib: Fix some more Golint warnings 2016-03-23 10:10:28 +01:00
Bjørn Erik Pedersen faf2e50685 Do some minor code cleaning of Site
* Unexport some methods/fields
* Add some godoc

Still plenty to do here.
2016-03-23 09:43:04 +01: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 35b798247e Check returned error in Scratch-test 2016-03-22 23:40:39 +01:00
Cameron Moore b1b7ac7e75 hugolib: Use field keys in composite literals
Small fix in shortcode tests to use field keys in a composite literal.
2016-03-22 19:43:28 +01:00
Bjørn Erik Pedersen 048e07422d Add Scratch to shortcode
Fixes #2000
2016-03-21 21:11:20 -04:00
Bjørn Erik Pedersen de8fc8761a Re-render shortcode on template or data file change
Fixes  #1971
2016-03-21 21:09:25 -04:00
Bjørn Erik Pedersen 02effd9dc4 Protect against concurrent Scratch read and write
Fixes #2005
2016-03-21 20:42:27 +01:00
Bjørn Erik Pedersen 3529152efe Return early from appendThemeTemplates 2016-03-17 23:36:11 +01:00
Bjørn Erik Pedersen 70739c972e Remove unnecessary type conversions 2016-03-14 20:35:50 +01:00
Bjørn Erik Pedersen dea185aa9b hugolib: Remove unused code 2016-03-14 15:41:03 +01:00
Bjørn Erik Pedersen 0fb31e4a82 Create an alias from shortcode.Page.Site to shortcode.Site
Fixes #1976
2016-03-14 14:10:15 +01:00
Bjørn Erik Pedersen 542e220cc4 Make tests green on both Pygments 2.0.2 and 2.1.3
See #1969
2016-03-13 22:06:51 +01:00
Bjørn Erik Pedersen cafb784799 Add emoji support
This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use `strings.Replacer` is also plenty fast.

```
BenchmarkEmojiKyokomiFprint-4  	   20000	     86038 ns/op	   33960 B/op	     117 allocs/op
BenchmarkEmojiKyokomiSprint-4  	   20000	     83252 ns/op	   38232 B/op	     122 allocs/op
BenchmarkEmojiStringsReplacer-4	  100000	     21092 ns/op	   17248 B/op	      25 allocs/op
BenchmarkHugoEmoji-4           	  500000	      5728 ns/op	     624 B/op	      13 allocs/op
```

Fixes #1891
2016-03-11 15:51:37 -06:00
Ján Koščo be3519fac0 Use default sitemap configuration for homepage
Fixes #1304
2016-03-10 11:02:00 +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 973393c99e Create template clone for late template execution
Fixing some breaking blogs on Go 1.6

Fixes #1879
2016-03-09 14:37:58 +01:00
Bjørn Erik Pedersen 9896cd0030 Add reference to parent shortcode
Fixes #1936
2016-03-09 11:06:40 +01:00
Bjørn Erik Pedersen c7acc318b5 Add some missing resets on rebuild
Fixes #1928
Fixes #1929
2016-03-06 16:33:32 +01:00
Bjørn Erik Pedersen eaba04e82b Add list support in Scratch 2016-03-06 15:44:17 +01:00
Bjørn Erik Pedersen 4e32dc80a2 Simplify the IsHome test cases 2016-03-06 00:41:11 +01:00
Bjørn Erik Pedersen 023992abad Unexport the target handlers
These are of no interest outside the package.
2016-03-05 20:56:38 +01:00
Bjørn Erik Pedersen 27f8d8f963 Allow URL with extension in frontmatter
Fixes #1923
2016-03-05 20:50:53 +01:00
Bjørn Erik Pedersen 8aa90f2b7e Try both prepped and unprepped taxonomy keys
Fixes #1869
2016-03-03 22:01:09 +01:00
Bjørn Erik Pedersen ccd2f4c32b Prevent capitalized taxonomy labels
Fixes #1880
2016-03-03 21:54:23 +01:00
Bjørn Erik Pedersen 7f682d7802 Fix shortcode handling in RST
Fixes #1904
2016-03-01 11:04:25 +01:00
Bjørn Erik Pedersen 6b922750f3 Revert "Create template clone for late template execution"
This reverts commit 93b04e67f6.
2016-02-28 12:15:33 +01:00
Bjørn Erik Pedersen 93b04e67f6 Create template clone for late template execution
Fixing some breaking blogs on Go 1.6

Fixes #1879
2016-02-28 11:51:51 +01:00
Bjørn Erik Pedersen 804603155f Check for the presence of pages before setting dates
See #1903
2016-02-27 23:25:41 +01:00
Bjørn Erik Pedersen 75cf324322 Set Date and Lastmod for main home page
Fixes #1903
2016-02-27 23:21:07 +01:00
Bjørn Erik Pedersen 455df10752 Optimize replaceShortcodeTokens
We can of course skip reading the entire byte slice again and again.

This was a slip in the original implementation; functionally the same,
but is slightly faster, esp. for larger data sets with many shortcodes:

```
benchmark                             old ns/op     new ns/op     delta
BenchmarkReplaceShortcodeTokens-4     15505         14753         -4.85%

benchmark                             old allocs     new allocs     delta
BenchmarkReplaceShortcodeTokens-4     1              1              +0.00%

benchmark                             old bytes     new bytes     delta
BenchmarkReplaceShortcodeTokens-4     3072          3072          +0.00%
```
2016-02-25 23:50:43 +01:00
Bjørn Erik Pedersen 8375995378 Enlarge data in BenchmarkReplaceShortcodeTokens 2016-02-25 21:45:13 +01:00
Tatsushi Demachi e9853642e5 Listen channel before sending values to it
The 'results' channel is not listend before sending error values in a
loop checking IsRenderable or not. This fixes it.
2016-02-20 14:03:06 +09:00
Bjørn Erik Pedersen 50182cd06b Remove superfluous Errorf 2016-02-16 02:05:59 +01:00