Commit graph

600 commits

Author SHA1 Message Date
Anthony Fok
d05b297e61 Add helpers.NormalizeHugoFlagsFunc() to handle flag name changes
It currently handles --baseUrl to --baseURL, and --uglyUrls to --uglyURLs.

Special thanks to Eric Paris (@eparis) for writing the
"normalized name" support in Cobra, and for showing us
how it is used in Kubernetes.

See Issue #959
2015-09-13 05:20:14 -06:00
coderzh
0e1fd78fb2 WordCount Summary support UTF-8 string 2015-09-12 15:41:17 +02:00
chrongzhang
52d94fa675 Add config option "disablePathToLower"
Enabling this prevents lowercasing of the path/url.

Fixes #557
2015-09-01 15:26:02 +02:00
Bjørn Erik Pedersen
5b90b388cb Unexport FileAndExt
If needed outside helpers, create an exported file path (FilePathAndExt?)  and/or a url version.
2015-08-26 21:29:32 +02:00
Bjørn Erik Pedersen
b05a292c21 Revert "Fix some Go code doc issues"
This reverts commit de7dd70bbc.

Broke the code fence feat.
2015-08-07 20:09:40 +02:00
Bjørn Erik Pedersen
de7dd70bbc Fix some Go code doc issues 2015-08-06 22:58:10 +02:00
Anthony Fok
4a2eda49cd Add option to disable Blackfriday Smartypants
Can be used in site config or per page front matter:

```
[blackfriday]
smartypants = false
```
2015-08-04 21:42:32 +02:00
Baptiste Mathus
b23b546a30 Asciidoc[tor]: use --no-header-footer option
This simplifies the retrieval of the HTML (no more need to extract the
part within body) and also removes the unwanted "Last Updated" part in
the article.
2015-07-29 17:36:19 +02:00
Bjørn Erik Pedersen
77c60a3440 Add RuneCount to Page
Fixes #1266
2015-07-12 11:05:37 +02:00
Andrew Brampton
c139c6e1ef Add support for GitHub-flavoured markdown code fences for highlighting
This commit adds a new PygmentsCodeFences config option (default false), which if true will allow GitHub style backtick code fences around code, which will then be rendered by Pygments.

For example:

``` language
your code
```

can be used instead of {{< highlight language >}}your code {{< /highlight >}}.

Fixes #362
2015-07-08 08:12:52 +02:00
Andrew Brampton
fdab118010 If no language is provided to Pygments, then try and guess it
Previously if no language was specified, then illegal args would be passed to pygments, for example `pygments -l -fhtml`, which would result in pygments printing an error.
2015-07-08 08:12:06 +02:00
Bjørn Erik Pedersen
483fc8fa3d Add config option for Blackfriday HTML_HREF_TARGET_BLANK
Fixes #1220
2015-06-28 15:18:15 +02:00
Bjørn Erik Pedersen
05c07c561a Add option to disable Blackfriday LaTeX style dashes
Can be used in site config of per page front matter:

```
[blackfriday]
latexDashes = false
```

Fixes #1231
2015-06-28 15:08:52 +02:00
Jonathan Anderson
1058cb17d1 Refactor theme path helper functions.
Reduce duplication (`x + FilePathSeparator + y` a few lines away from `filepath.Join(x, y)`) and add a `GetThemeDir()` function to get the current theme's directory.

Also add a comment complaining about the `GetThemesDirPath()` function, which doesn't seem to do what its name would suggest. This might be a candidate for deprecation?
2015-06-25 18:05:43 +02:00
Bjørn Erik Pedersen
50269f2512 Remove superfluous return 2015-06-16 22:31:51 +02:00
Bjørn Erik Pedersen
4b7c1342fd Make removal of accents in taxonomy and section paths optional
And default off.

Fixes #1180
2015-06-16 19:25:48 +02:00
Vincent Batoufflet
82cc1ac0f8 Add Blackfriday definition lists extension support 2015-06-15 21:15:05 +02:00
bep
beeae6ab69 Add some tests for IgnoreFiles
And log error on invalid regexp.

See #1189
2015-06-03 18:54:15 +02:00
bep
3ea4df35f2 Remove accents in URLs
So the taxonomy `Gérard Depardieu` gives paths on the form `gerard-depardieu`.

Unfortunately this introduces two imports from the `golang.org/`, but Unicode-normalization isn't something we'd want to write from scratch.

See https://blog.golang.org/normalization

See #1180
2015-05-31 20:30:45 +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
bep
be964e95a1 Never remove trailing slash in RelPermalink
Fixed #1174
2015-05-27 20:41:43 +02:00
bep
beaa008c2f Make deprecated warning for this release more alert 2015-05-26 23:08:25 +02:00
bep
be381683ff Hyphenate DEV version 2015-05-26 22:44:39 +02:00
spf13
d4de261508 bumping master version to v0.15-DEV 2015-05-25 21:46:29 -04:00
spf13
6af9d6789e Bump version to Hugo v0.14.0 2015-05-25 11:59:47 -04:00
bep
beee679dfb Unexport filepath/path bridge types
They are of no use outside the helpers package.

See #1160
2015-05-25 13:10:40 +02:00
bep
be79c35bda Pass RenderingContext by reference in Mmark 2015-05-25 12:57:58 +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
beaa8b1bca Add support for URLs relative to context root
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative.

And will do so with speed.

So:

In `/post/myblogpost.html`:

`/mycss.css` becomes `../mycss.css`

The same in `/index.html` will become:

`./mycss.css` etc.

Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`).

The speediness is about the same as before:

```
benchmark                    old ns/op     new ns/op     delta
BenchmarkAbsURL              17462         18164         +4.02%
BenchmarkAbsURLSrcset        18842         19632         +4.19%
BenchmarkXMLAbsURLSrcset     18643         19313         +3.59%
BenchmarkXMLAbsURL           9283          9656          +4.02%

benchmark                    old allocs     new allocs     delta
BenchmarkAbsURL              24             28             +16.67%
BenchmarkAbsURLSrcset        29             32             +10.34%
BenchmarkXMLAbsURLSrcset     27             30             +11.11%
BenchmarkXMLAbsURL           12             14             +16.67%

benchmark                    old bytes     new bytes     delta
BenchmarkAbsURL              3154          3404          +7.93%
BenchmarkAbsURLSrcset        2376          2573          +8.29%
BenchmarkXMLAbsURLSrcset     2569          2763          +7.55%
BenchmarkXMLAbsURL           1888          1998          +5.83%

```

Fixes #1104
Fixes #622
Fixes #937
Fixes #157
2015-05-16 00:11:44 +02:00
bep
bec839e652 Add relURL template func
Fixes #1126
2015-05-11 13:59:02 +02:00
bep
be0cbeee7f Add absURL template func
Fixes #1106
2015-05-11 12:28:35 +02:00
bep
bec90e0850 Make page 1 alias ugly
When `uglyurls = true`

Fixes #1121
2015-05-10 18:28:44 +02:00
bep
a52e508d46 Update test logs for uniformity and consistency
Many minor fixes to make test logs more consistent and correct a
mispelling.

Standardize on "[%i] got X but expected Y" for log messages. Using
a consistent layout makes it easier to read the test results. This
was mostly changing "Got" to "got". Swapped the order of values on
several calls to bring them in line with the convention.

A few log messages had a sequence number added to identify the
exact scenario that failed. Otherwise, there would be no way to
ascertain which failed When there are many scenarios.

Correct spelling of "expected."

Fixes #1028
Merged be2097e1ad

[close #1040]
2015-05-08 22:27:00 -04:00
Anthony Fok
563a6302a0 Very experimental support for mmark
Either name the content files as `*.mmark`,
or add `markup = "mmark"` in the front matter
of your `*.md` content files.
2015-05-08 22:05:41 -04:00
Yosuke INOUE
3596b1b810 Add blackfriday/ExtensionsMask option. 2015-05-07 21:12:28 +02:00
Andrew Gallant
ee5a1bbf44 Allow 'classprefix' pygments options. 2015-05-07 03:45:51 +02:00
bep
bea9280fb3 Do not add trailing slash to baseURL
Fixes #1105
2015-05-05 16:02:44 +02:00
bep
be7b830f33 tpl: add sanity check to prevent panic in seq on big nums
Fixes #1092
2015-04-30 13:25:46 +02:00
bep
be29c0bfbd Print ERROR on theme vs Hugo version mismatch
Fixes #1070
2015-04-28 20:39:25 +02:00
bep
be0d977009 Only write highlight to cache when CacheDir is set
To avoid writing cache files when testing.
2015-04-16 02:27:23 +02:00
bep
be24457acf Add more options to highlight
Fixes #1021
2015-04-15 20:31:06 +02:00
bep
be540f5b8f Fix potential Windows path issue with Pygments cache 2015-04-14 19:58:33 +02:00
bep
beb66c19a4 helpers: add some missing documentation 2015-04-03 22:30:08 +02:00
bep
bea42218b6 helpers: fix some go vet errors 2015-04-03 21:20:25 +02:00
bep
bea5feb34d Return early from DistinctErrorLogger's Printf 2015-04-03 21:16:32 +02:00
Dylan MacKenzie
99a18b21fc List directories being watched when server is run
Fixes part of issue 1030. Previously hugo only listed the content
directory as being watched. Now we list all files being watched
according to `commands.getDirList()`. We also introduce a RemoveSubpaths
function and test in the helpers module to reduce noise in the command
line output by not showing subdirectories of ones already being watched.

For example, instead of:
`Watching for changes in $HOME/blog/content`
We get:
`Watching for changes in
$HOME/blog/{data,content,layouts,static,themes/my-theme}`
2015-04-02 12:52:08 +02:00
bep
bec4bdae99 Return error on wrong use of the Paginator
`Paginate`now returns error when

1) `.Paginate` is called after `.Paginator`
2) `.Paginate` is repeatedly called with different arguments

This should help remove some confusion.

This commit also introduces DistinctErrorLogger, to prevent spamming the log for duplicate rendering errors from the pagers.

Fixes #993
2015-03-31 22:33:17 +02:00
bep
be21e2cbed Add some more corner tests for ReaderContains 2015-03-30 01:22:09 +02:00
bep
be6696c34b Handle views in combo with Ace base templates
As views looks like a regular template, but doesn't need a base template, we have to look inside it.

Altough really not needed by this commit, reading the full file content into memory just to do a substring search is a waste.
So this commit implements a `ReaderContains` func that in most cases should be much faster than doing an `ioutil.ReadAll` and `bytes.Contains`:

```
benchmark                   old ns/op     new ns/op     delta
BenchmarkReaderContains     78452         20260         -74.18%

benchmark                   old allocs     new allocs     delta
BenchmarkReaderContains     46             20             -56.52%

benchmark                   old bytes     new bytes     delta
BenchmarkReaderContains     46496         1258          -97.29%
```

Fixes #999
2015-03-29 21:12:13 +02:00
Ruben Vermeersch
e8ca8602c0 Hash all pygments parameters.
Ensures that Hugo rehighlights source code whenever one of the
highlighting options changes.
2015-03-29 13:01:44 +02:00
Ruben Vermeersch
15463d3d45 Cache pygments rendering between runs
Fixes #1000
2015-03-27 19:50:48 +01:00
bep
9688ed2585 Comment out shaky Seq test 2015-03-18 12:42:00 +01:00
bep
f4244be036 Calculate the next Hugo version in Deprecated
Deprecation will be an ongoing activity for many future versions.
2015-03-18 12:27:56 +01:00
bep
3273fce044 Refactor Hugo version
Put version handling into the helpers package so it can be used by many,
and split version and suffix to make it possible to calculate the next Hugo version.
2015-03-18 12:23:13 +01:00
bep
e39a258ec4 Improve type handling in Seq 2015-03-18 11:30:37 +01: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
bep
0be2aade99 Add Seq template func
Very similar to GNU's seq.

Fixes #552

Conflicts:
	tpl/template.go
2015-03-12 22:08:36 -04:00
Anthony Fok
358dcce7a6 Experimental AsciiDoc support with external helpers
See #470

 * Based on existing support for reStructuredText files

 * Handles content files with extensions `.asciidoc` and `.ad`

 * Pipes content through `asciidoctor --safe -`.
   If `asciidoctor` is not installed, then `asciidoc --safe -`.

 * To make sure `asciidoctor` or `asciidoc` is found, after adding
   a piece of AsciiDoc content, run `hugo` with the `-v` flag
   and look for this message:

        INFO: 2015/01/23 Rendering with /usr/bin/asciidoctor ...

Caveats:

 * The final "Last updated" timestamp is currently not stripped.

 * When `hugo` is run with `-v`, you may see a lot of these messages

        INFO: 2015/01/23 Rendering with /usr/bin/asciidoctor ...

   if you have lots of `*.ad`, `*.adoc` or `*.asciidoc` files.

 * Some versions of `asciidoc` may have trouble with its safe mode.
   To test if you are affected, try this:

        $ echo "Hello" | asciidoc --safe -
        asciidoc: ERROR: unsafe: ifeval invalid
        asciidoc: FAILED: ifeval invalid safe document

   If so, I recommend that you install `asciidoctor` instead.

Feedback and patches welcome!

Ideally, we should be using https://github.com/VonC/asciidocgo,
@VonC's wonderful Go implementation of Asciidoctor.  However,
there is still a bit of work needed for asciidocgo to expose
its API so that Hugo can actually use it.

Until then, hope this "experimental AsciiDoc support through external
helpers" can serve as a stopgap solution for our community. :-)

2015-01-30: Updated for the replaceShortcodeTokens() syntax change
2015-02-21: Add `.adoc` extension as suggested by @Fale

Conflicts:
	helpers/content.go
2015-03-12 22:01:49 -04:00
bep
b190ad0ff9 source: add some test cases for File 2015-03-12 20:50:44 +01:00
bep
f8a840a14c Add double checking in Deprecated
To prevent possible duplicate log statements.
2015-03-12 18:51:31 +01:00
bep
6e30c10d09 Add deprecated logger 2015-03-12 16:10:34 +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
bd2b679eaf helpers: apply some Golint rules 2015-03-07 00:02:06 +01:00
bep
e685dfc0c6 Apply some more Golint suggestions 2015-03-06 18:07:50 +01:00
bep
103ea842f8 Fix errors reported by Go Vet 2015-03-06 15:25:19 +01:00
bep
9d80ecb4d8 Keep trailing slash when baseUrl contains a sub path
Before this commit, .Site.BaseUrl ended up as:

http://mysite.com/ => http://mysite.com/
http://mysite.com/sub/ => http://mysite.com/sub

Now it becomes:

http://mysite.com/ => http://mysite.com/
http://mysite.com/sub/ => http://mysite.com/sub/

Fixed #931
2015-02-28 18:45:02 +01:00
Cyrill Schumacher
a3892685bc Add trailing file separator to temp dir
Make sure that the file separator is added to the temp dir in all cases.

This prevents cache temp files being written to the root temp folder.

Fixes #910
2015-02-19 14:16:04 +01:00
Anthony Fok
c4393257e8 Adapt to relative path bug fix in purell
Temporary workaround for the bug fix and resulting
behavioral change in purell.NormalizeURLString():
a leading '/' was inadvertently to relative links,
but no longer, see #878.

I think the real solution is to allow Hugo to
make relative URL with relative path,
e.g. "../../post/hello-again/", as wished by users
in issues #157, #622, etc., without forcing
relative URLs to begin with '/'.
Once the fixes are in, let's remove this kludge
and restore SanitizeUrl() to the way it was.

Fixes #878
2015-02-17 12:31:39 -05:00
Cyrill Schumacher
41a5168198 Fix bug on windows where the backslash got removed in func MakePath() 2015-02-17 12:14:39 -05:00
Cyrill Schumacher
5e2d3d2e10 Merge to stay up to date with current dev
Feature: GetJson and GetJson in short codes or other layout files.
For more details please see: http://cyrillschumacher.com/2014/12/21/dynamic-pages-with-gohugo.io/
2015-02-17 12:14:39 -05:00
bep
ebcc1e6699 Add data files support in themes
If duplicate keys, the main data dir wins.

Fixes #892
2015-02-11 20:24:56 +01:00
bep
fa71f6c11e Make # survice Url cleaning
To enable anchors in Urls.

Fixes #888
2015-02-10 19:14:19 +01:00
bep
08219161dd Use buffer pool in StripHTML
Allocates less memory:

benchmark              old ns/op     new ns/op     delta
BenchmarkStripHTML     6572          6695          +1.87%

benchmark              old allocs     new allocs     delta
BenchmarkStripHTML     5              4              -20.00%

benchmark              old bytes     new bytes     delta
BenchmarkStripHTML     848           737           -13.09%

Compared to 0.12:

benchmark              old ns/op     new ns/op     delta
BenchmarkStripHTML     10210         6695          -34.43%

benchmark              old allocs     new allocs     delta
BenchmarkStripHTML     6              4              -33.33%

benchmark              old bytes     new bytes     delta
BenchmarkStripHTML     1456          737           -49.38%
2015-02-06 15:35:45 +01:00
bep
43e48a8989 Add benchmark test for StripHTML
go test -test.run=NONE -bench=".*" -test.benchmem=true ./helpers

Old vs new impl (string.Replace vs string.Replacer):

benchmark              old ns/op     new ns/op     delta
BenchmarkStripHTML     10210         6572          -35.63%

benchmark              old allocs     new allocs     delta
BenchmarkStripHTML     6              5              -16.67%

benchmark              old bytes     new bytes     delta
BenchmarkStripHTML     1456          848           -41.76%
2015-02-06 10:00:42 +01:00
bep
48b6777ea2 Fix Truncate
TruncateWordsToWholeSentence knows if the summary is truncated, so let "him" decide.

Fixes #880
2015-02-05 14:04:48 -07:00
bep
2bee4a1570 Replace 4 strings.Replace with 1 strings.Replacer
Consumes less memory, slightly faster.
2015-02-05 18:31:11 +01:00
bep
f8704c1bf2 Avoid calling strings.Fields multiple times with same content
This should be a relief for big sites.
2015-02-05 00:38:50 +01:00
Naoya Inada
d1364ffb68 Fix defaults for Blackfriday 2015-01-31 22:06:50 +01:00
bep
420c9e4d3d Add writable context to Node
The variable scope in the Go templates makes it hard, if possible at all, to write templates with counter variables or similar state.

This commit fixes that by adding a writable context to Node, backed by a map: Scratch.

This context has three methods, Get, Set and Add. The Add is tailored for counter variables, but can be used for any built-in numeric values or strings.
2015-01-31 22:01:30 +01:00
spf13
e1e6aaed2f Merge branch 'master' of github.com:spf13/hugo 2015-01-31 01:04:28 -05:00
spf13
66ed5c5e02 Adding BufferPool. Implementing BP in ReaderTo{Bytes,String}(). 2015-01-30 11:12:07 -08:00
Dan Hersam
523f38a9a8 Fix for issue 839 and 490 on Windows
The paths were seen as changed but not static because of the backslashes in
ev.Name. Once the backslashes were added, I discovered that the JSON
sent to livereload was invalid and failed to work because it had backslashes.

Hence the code to replace the backslashes from the path to make them work
in JSON and for the URL.

With this fix, changes to a stylesheet are shown on the page, and if it's a
single file that changed, it's reflected in the browser without reloading the whole
page.
2015-01-30 14:18:17 +01:00
fundon
ee1045ad42 ignore root path, no need strip traling slash 2015-01-28 09:43:43 +01:00
bep
e52a76f559 Use runtime.GOOS to identify Windows specific path tests 2015-01-27 23:01:32 +01:00
bep
251f5e9d40 Do not panic on permission denied
Replace panic with FATAL logging and graceful shutdown.

Fixes #837
2015-01-27 16:51:24 +01:00
bep
8ad4fd05d8 Split Windows and Unix specific path tests 2015-01-27 15:09:01 +01:00
bep
b155e8b4cb Temporarily comment out breaking Windows test case 2015-01-27 12:12:35 +01:00
bep
bedc2d8488 Introduce FilepathPathBridge
This commit introduces the new interface FilepathPathBridge to remove some code that differs only in their use of either the path or filepath package.
2015-01-27 11:44:41 +01:00
bep
5f9596e68c Add more tests to helper 2015-01-27 10:15:57 +01:00
bep
37445bc6aa Add pagination support for home page, sections and taxonomies
Two new configuration properties, `Paginate` (default `0`) and `PaginatePath` (default `page`) are added.

Setting `paginate` to a positive value will split the list pages for the home page, sections and taxonomies into chunks of size of the `paginate` property.

A `.Paginator` is provided to help building a pager menu.

There are two ways to configure a `.Paginator`:

1. The simplest way is just to call `.Paginator.Pages` from a template. It will contain the pages for "that page" (`.Data.Pages` will (like today) contain all the pages).
2. Select a sub-set of the pages with the available template functions and pass the slice to `.Paginate` : `{{ range (.Paginate (where .Data.Pages "Type" "post")).Pages }}`

**NOTE:** For a given Node, it's one of the options above. It's perfectly legitimate to iterate over the same pager more than once, but it's static and cannot change.

The `.Paginator` contains enough information to build a full-blown paginator interface.

The pages are built on the form (note: BLANK means no value, i.e. home page):

```
[SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/1/index.html => redirect to  [SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/2/index.html
....
```

Fixes #96
2015-01-26 12:59:37 +01:00
Naoya Inada
407e80a9ab Add site-wide/per-page [blackfriday] extensions option 2015-01-26 09:55:37 +01:00
Anthony Fok
f6c0b472e9 Make Blackfriday smart fractions to really default to true
Fix my own bug in Pull Request #829,
commit eb686352b1
2015-01-24 22:06:15 +01:00
Anthony Fok
eb686352b1 Add site-wide/per-page [blackfriday] fractions option
Make Blackfriday's `HTML_SMARTYPANTS_FRACTIONS` option
user-configurable.  Defaults to `true` as before.  See
discussions at:

http://discuss.gohugo.io/t/any-way-to-disable-smart-fractions/328

Thanks to @bjornerik and @spf13 for laying the groundwork
making it easy to expose Blackfriday's underlying configurable
options.
2015-01-24 20:57:40 +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
Anthony Fok
19c52ab0b5 Register rstHandler to restore experimental reST support
(Experimental) reStructuredText support was working in v0.12,
but was no longer handled after some refactoring in v0.13-DEV.
That experimental support is now restored.

Furthermore, check for both rst2html and rst2html.py in the PATH,
and execute whichever is found.

See #472 for more information.
2015-01-21 06:41:19 -07:00
bep
2ec046afb1 Minor polish in path/url 2015-01-20 20:45:03 +01:00
bep
9e688507a7 Add more tests to general helper 2015-01-20 18:13:47 +01:00
Marek Stanley
49f5eb5c84 Moved a test regarding a content.go function to a new test file content_test.go.
Added some tests for general helpers, especially as a way to document the expected behavior,
and as a warm-up welcome contribution.
2015-01-09 12:42:13 +01:00
Jacob Gillespie
c0f54aefe3 Rename to plainIdAnchors 2015-01-05 21:00:22 +01:00
Jacob Gillespie
4adf58cce7 Group both options under Blackfriday: documentIDAnchor 2015-01-05 21:00:22 +01:00
Jacob Gillespie
b7716948bc Add config options: disable footnote anchor prefix and header ID suffix
New config options:

* DisableFootnoteAnchorPrefix - bool - default: false
* DisableHeaderIDSuffix - bool - default: false
2015-01-05 21:00:22 +01:00
Anthony Fok
f5a3fb149f Wrap comments helpers package to fit 80-column width
Add an initial space after `//` where appropriate.
Minor copyediting.
2014-12-26 08:07:03 -07:00
bep
fbf8bcacc4 Add configurable support for angled quotes
The flag `HTML_SMARTYPANTS_ANGLED_QUOTES` was added to Blackfriday on Black Friday. This configures rendering of double quotes as angled left and right quotes (&laquo;
&raquo;).

Typical use cases would be either or, or combined, but never in the same
document. As an example would be a person from Norway; he has a blog in both
English and Norwegian (his native tongue); he would then configure Blackfriday
to use angled quotes for the Norwegian section, but keep them as reqular
double quotes for the English.

This commit adds configuration support for this new flag, configuration that can be set in the site configuration, but overridden in page front matter.

Fixes #605
2014-12-26 14:31:55 +01:00
Ahsanul Haque
14bce119b6 Commented helpers package 2014-12-18 22:18:36 -05:00
Ahsanul Haque
2c8e9a7931 Commenting helpers package 2014-12-12 02:57:25 +06:00
bep
9f77f93071 Fix various Windows-issues
File handling was broken on Windows. This commit contains a revision of the path handling with separation of file paths and urls where needed.

There may be remaining issues and there may be better ways to do this, but it is easier to start that refactoring job with a set of passing tests.

Fixes #687
Fixes #660
2014-12-09 09:43:15 -05:00
Austin Ziegler
8f9cea7f58 Enable descriptive header IDs.
Enable blackfriday.EXTENSION_AUTO_HEADER_IDS to generate the name of the
header ID from the text in the header. Works for prefix and underline
headers.

- TOC extraction had to be modified to look for `<li><a href="#`>
  instead of `#toc_` because of this change.
- Fixed a number of tests that depended on the presence of `toc_` with
  as an `id` or as a `href` value.
- Renames the earlier parameter `footnoteref` to `documentId` as it more
  accurately represents the nature of the parameter. The `documentId` is
  appended to all generated headers through the new HTML renderer
  parameter `HeaderIDSuffix`.
2014-11-24 18:01:57 -05:00
bep
55fcd2f30f Shortcode rewrite, take 2
This commit contains a restructuring and partial rewrite of the shortcode handling.

Prior to this commit rendering of the page content was mingled with handling of the shortcodes. This led to several oddities.

The new flow is:

1. Shortcodes are extracted from page and replaced with placeholders.
2. Shortcodes are processed and rendered
3. Page is processed
4. The placeholders are replaced with the rendered shortcodes

The handling of summaries is also made simpler by this.

This commit also introduces some other chenges:

1. distinction between shortcodes that need further processing and those who do not:

* `{{< >}}`: Typically raw HTML. Will not be processed.
* `{{% %}}`: Will be processed by the page's markup engine (Markdown or (infuture) Asciidoctor)

The above also involves a new shortcode-parser, with lexical scanning inspired by Rob Pike's talk called "Lexical Scanning in Go",
which should be easier to understand, give better error messages and perform better.

2. If you want to exclude a shortcode from being processed (for documentation etc.), the inner part of the shorcode must be commented out, i.e. `{{%/* movie 47238zzb */%}}`. See the updated shortcode section in the documentation for further examples.

The new parser supports nested shortcodes. This isn't new, but has two related design choices worth mentioning:

* The shortcodes will be rendered individually, so If both `{{< >}}` and `{{% %}}` are used in the nested hierarchy, one will be passed through the page's markdown processor, the other not.
* To avoid potential costly overhead of always looking far ahead for a possible closing tag, this implementation looks at the template itself, and is branded as a container with inner content if it contains a reference to `.Inner`

Fixes #565
Fixes #480
Fixes #461

And probably some others.
2014-11-17 18:32:06 -05:00
bep
91e03b9fbc Reinsert deleted test
This test was deleted by mistake in owenwaller's contribution to add more tests.

I haven't looked closer, there may be more missing.
2014-11-13 22:47:06 -05:00
Joel Scoble
ca4e4ce2f9 converted helpers usage of path 2 filepath 2014-11-13 22:41:59 -05:00
spf13
cafd39eb9b Fixing some tests 2014-11-04 20:28:27 -05:00
spf13
55fb02428d Updating tests to use hugofs 2014-11-04 20:28:07 -05:00
spf13
a40bd3caf1 rewriting guessSection to accurately reflect intent and usage. Update tests. 2014-11-04 20:19:45 -05:00
Owen Waller
e2634752ce First stab at correcting GuessSection tests
Updated the test to correctly test for "" when a non-absolute path
is used.

But the tests still fail for multi-part paths e.g. /contents/blog/
2014-11-04 19:19:27 -05:00
Owen Waller
f81f9ceb40 Fix: rewrite FileAndExt
FileAndExt has now be completely rewritten and now works as may
reasonably be expected. The test cases for:

ReplaceExtension
Filename
FileAndExt

now all pass.

The problem was the way path.Base was being used.
Firstly Base returns "." if the directory is empty, but it can also
return "." for the current directory, or ".." for the parent directory,
if these are the last elements in the path. Simply detecting the
presence of a "." in the returned string and truncating before the "."
does not therefore always result in a valid filename.
Secondly, Base strips any trailing slashes making is more difficult to
detect when the path does not end in a filename but in a directory name
i.e. a no filename case. Not detecting this incorrectly results in the
last directory name being returned as the filename.

The code has been updated to take account of of both situations so that:
1) An empty string for both the filename and extension is returned if the
path does not contain a filename (plus an optional extension). This
includes both the empty path case, and the ends in a directory case.
2) If the path represents a filename with an extension then both the
filename and the extension (minus any dots) are returned as non empty
strings.
3) If the path represents a filename without an extension then filename
will be returned as a non empty string (minus any dot) and the extension
will be returned as an empty string.
2014-11-04 19:19:19 -05:00
Owen Waller
5906c8652d Fix: remove the unnecessary dot in an extension
Oops minor typo. The new extension passed to ReplaceExtension should
not have a dot in it. The test data bas been updated to reflect this.
2014-11-04 19:19:09 -05:00
Owen Waller
3521e8b1e5 Updated TestReplaceExtensioni, TestFilename and TestFileAndExt
Updated the test cases in TestReplaceExtension to reflect the intent
of ReplaceExtension which is to accept a path and return only the file
name with a new extension. It's intentionally designed to strip out the
path and only provide the filename

Additional test cases have been added to both TestFilename and
TestFileAndExt to clarify behaviour with relative paths.
2014-11-04 19:19:01 -05:00
Owen Waller
980d0f14de WriteToDisk and SafeWriteToDisk test cleaned up
Minor cleanup to randomise the names of the temp directories used by the
tests.
2014-11-04 19:18:54 -05:00
Owen Waller
bf07dc9293 WriteToDisk and SafeWriteToDisk tests now pass
This is the first time that both the WriteToDisk and SafeWriteToDisk
tests pass
2014-11-04 19:18:46 -05:00
Owen Waller
a54ad2bf39 Fix: Test TestSafeWriteToDisk now works
Oops, my bad.
Despite the function intending to test SafeWriteToDisk it was actually
calling WriteToDisk. WriteToDisk does not return the file exists error
that SafeWriteToDisk does, which the test checks for.
2014-11-04 19:18:36 -05:00
Owen Waller
e8bbc44ab0 Added the path modules test files
Added the new path modules test file. This replaces the old
helpers_test.go file.

The currently failing tests are:
TestReplaceExtension
TestFilename
TestFileAndExt
TestGuessSection
TestFindCWD
TestWriteToDisk

In addition the TestSafeWriteToDisk test case is currently disabled.
It will panic if enabled.

In addition there are some minor changes to path.go. They are:
Refactored MakePathToLower to simplify it.
Commented out, pending removal, Sanitize as it appears to be unused.
Fixed the resource leak in UnicodeSanitize

Conflicts:
	helpers/path.go
2014-11-04 19:18:04 -05:00
Owen Waller
6b619d2cd6 Added the url modules test files.
Added the new url module test file. This replaces the original
helpers_test.go file.

The TestUrlPrep test currently fails.

The only minor change to url.go is to add some trace printf's to
UrlPrep.
2014-11-04 19:16:07 -05:00
Owen Waller
57cd953997 Added the general modules test files
Added the new general module's test file, general_test.go. This replaces the
helpers_test.go file.

There is also a minor defect fix in general.go's StripHTML function.
The correct xhtml tag for a break is <br /> not </br>. I've also removed
the unnecessary spaces before the replacement "\n".

The new test module also reflects this change.

Conflicts:
	helpers/general.go
2014-11-04 11:13:41 -05:00
Owen Waller
b87402e8cd Remove the helpers_test.go file
The helpers_test.go file has been split into three new
test files, one each for the path, url and general modules.

Conflicts:
	helpers/helpers_test.go
2014-11-04 11:10:55 -05:00
spf13
dcea0fa5ce Adding ReaderTo and ToReader helper functions 2014-11-04 00:26:56 -05:00
spf13
141f3e19e0 Migrating Hugo to Afero for filesystem calls. 2014-11-01 11:57:29 -04:00
spf13
dfb8482569 Handlers WIP - Convert now working 2014-10-20 20:15:33 -04:00
spf13
5dfc1dedb8 Big refactor of how source files are used. Also added default destination extension option. 2014-10-16 20:20:09 -04:00
Jian Zhou
d064139cee Fix spf13/hugo#467. RSSLink now point to index.xml 2014-10-15 12:36:06 -04:00
bep
df489b4712 Enable soft livereload of CSS and images
Prior to this commit a dummy JavaScript filename was sent to LiveReload when changing a static file (CSS, image etc.), forcing a full browser reload of the page.

This commit fixes this by sending the relative file path of the changed static resource, enabling partial live reloading for CSS- and image-changes. If more than one static file happens to end up in the same changeevent-batch, it will fall back to do a full refresh. To enable this logic, the change events with names ending with ".goutputstream*" is now filtered out as temporary.

Changes in dynamic content behaves like before.

Issue #490
2014-09-11 16:58:06 -04:00
Jakub Turski
1684579127 Go back to lowercase slugs. Also, use MakePathToLower in TestMakeToLower.
go fmt
2014-09-08 11:42:36 -04:00
spf13
30af267b32 Fix #302. Links now have trailing slashes. 2014-08-25 12:45:47 -04:00
Nate Finch
a31edb3388 Support subdir in baseurl.
Mainly this was a change to helpers.MakePermalink, but to get the local server to run correctly,
we needed to redirect the path of the request from /foo to /.  In addition, I added tests for the
server's code for fixing up the base url with different config file & CLI options.
2014-08-25 11:51:51 -04:00
Joel Scoble
4c735a7878 preserve alias case while lowercasing taxonomy 2014-08-25 10:16:59 -04:00
spf13
6b8244ba67 new site works in an empty directory now 2014-05-19 09:16:40 -04:00
spf13
296d218e67 Better handling of when the specified port is already in use 2014-05-15 17:41:03 -04:00
LK4D4
2194cc77de Add pygmentsstyle and pygmentsuseclasses options
Fixes #204

Conflicts:
	commands/hugo.go
2014-05-09 23:20:11 -04:00
spf13
bff1f1e689 Adding some new methods to helpers (GuessSection, MakeTitle & Filename) 2014-05-02 01:04:14 -04:00
spf13
58f8b43fee moving writeToDisk to helpers to make it more accessible 2014-05-01 13:13:11 -04:00
LordFPL
b52e946381 Little syntax mistake 2014-04-26 23:03:20 -06:00
spf13
ad34be9d77 strip trailing baseurl slash. Added a new template function "sanitizeurl" which ensures no double slashes. Fixed #221 2014-04-07 22:02:08 -04:00
spf13
62dd1d45c1 Hugo config abstracted into a general purpose config library called "Viper".
Hugo casting now in own library called "cast"
2014-04-05 01:40:33 -04:00
spf13
e50b9d8ac1 Adding support for logging & verbose logging. Consolidation of error handling. Integration of jWalterWeatherman library. Fixed #137 2014-03-31 13:23:34 -04:00
Mike Keesey
2540d884d8 Fixing issues go vet reports. 2014-03-01 09:56:17 -05:00
spf13
14227351fa Reorganization of helpers. Centralized Url/Path logic. Fixed #175. 2014-02-27 20:33:18 -05:00
Anton Ageev
11ca84f8cb Add unicode support for aliases, indexes, urlize template filter.
Now aliases and indexes are not restricted ASCII letters and can include
any unicode letters.
2014-02-05 11:49:57 -05:00
Tibor Vass
6dd2e9a49a gofmt all go code 2014-01-29 18:03:35 -05:00
spf13
01da9a40e6 Report error, but don’t fatally stop if pygments has error. Return original string. (+1 squashed commit)
Squashed commits:
[849a7af] if highlighting doesn’t work, just return original string
2014-01-10 21:28:48 -05:00
spf13
fa29e94edb Adding Pygments helper 2013-12-05 09:42:29 -05:00
spf13
44d57fdc0c Reorganize helpers 2013-12-05 09:29:41 -05:00