Commit graph

66 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 c8c6f5d05b Add json mime extension type 2016-03-06 14:10:06 +01:00
Bjørn Erik Pedersen 1f61f40328 Use flagChanged in all places 2016-02-27 18:01:01 +01:00
Bjørn Erik Pedersen 9349a889e2 Do not try to find available port if set by user
He/she probably really meant it.

Fixes #1901
2016-02-27 16:58:42 +01:00
Bjørn Erik Pedersen 74539dea87 Unexport the remaining vars in hugo command 2016-02-05 22:58:17 +01:00
Cameron Moore a89b2f41d6 commands: Get BaseURL from viper in server mode
Fixes #1821
2016-02-05 20:38:02 -06:00
Bjørn Erik Pedersen 87ca0d0cbe Clean flags
* Reduce the amount of global flags
* Unexport all flag vars and commands vars
* Some other minor flag cleaning
2016-02-05 21:18:45 +01:00
Steve Francia ed3015c350 update server to match latest afero 2016-01-11 21:45:05 -05:00
Anthony Fok de82404d35 Fix hugo server "Watching for changes" path display
especially when the given `--source` path is a relative directory.

Also, when `--source` is specified, make WorkingDir an absolute path
from the very beginning, to be consistent with the case when `--source`
is not given.  Otherwise, the function name helpers.AbsPathify(), which
prepends WorkingDir to a relative path, does not really make sense.

Fixes #1721
2015-12-19 05:19:31 -07:00
Anthony Fok 3574304c68 Improve some random feedback messages
Also clean up a couple random comments.
2015-12-16 21:26:51 -07:00
Bjørn Erik Pedersen e445c35d6a Fix copyright headers in source files
Still need to add some missing headers and an AUTHORS file.

See #1646
2015-12-07 19:57:01 +01:00
Anthony Fok cd062623bd Fix crash with "config", "check" and "benchmark"
The crash was introduced by commit 00d04774 in PR #1652
where access to NoTimes was attempted even though --noTimes
was not defined for the config, check and benchmark commands.

Special thanks to @bep for the heads-up!

See also #1624 - CLI UX: Flags shouldn't be global
2015-12-03 12:02:38 -07:00
Anthony Fok 00d04774f0 Change most global flags into local ones
This is to ensure that only the relevant command-line flags
for a certain Hugo subcommand is shown to the end user,
reducing clutter and improving user experience.

Fixes #1624 - CLI UX: Flags shouldn't be global
2015-12-03 00:36:38 -07:00
Anthony Fok d48781badf One more error fix in the server command
And some other small code clean-up.

See #1502
2015-12-02 11:56:36 -07:00
Bjørn Erik Pedersen 3f0f7eed68 Improve error handling in commands
Cobra, the CLI commander in use in Hugo, has some long awaited improvements in the error handling department.
This enables a more centralized error handling approach.

This commit introduces that by changing all the command funcs to `RunE`:

* The core part of the error logging, usage logging and `os.Exit(-1)` is now performed in one place and that one place only.
* The usage text is now only shown on invalid arguments etc. (user errors)

Fixes #1502
2015-12-02 07:07:05 -07:00
Steve Francia f045d7a611 Change the license to Apache 2.0 2015-11-23 22:16:36 -05:00
Bjørn Erik Pedersen 831e936846 Improve "watching for ..." logging 2015-11-23 16:32:06 +01:00
Anthony Fok 5c7234015d Copyedit long help message in commands/server.go 2015-11-21 06:31:10 -07:00
Steve Francia 97d0689580 Hugo server watch by default 2015-11-20 10:14:24 -05:00
Bjørn Erik Pedersen 3f5ddd5242 Revert "Disable render-to-memory on Windows"
This reverts commit 91e0c2b1fe.

This should now work.
2015-11-19 19:48:40 +01:00
Bjørn Erik Pedersen 91e0c2b1fe Disable render-to-memory on Windows
See #1586
2015-11-18 23:10:56 +01:00
spf13 df824fa31b Hugo server renders and serves from memory by default (30%+ improvement) 2015-11-16 22:00:11 -05:00
spf13 e1618e9d2f permit the notimes flag on hugo server 2015-11-16 21:56:14 -05:00
Anthony Fok 18a29964fa Fix trivial typos in code 2015-11-16 07:15:17 -07:00
spf13 a50133ff38 Improve the server usage output 2015-11-12 10:23:41 -05:00
spf13 bccf957e36 Add support for dynamic reloading of config file when watching 2015-11-09 23:31:52 -05:00
Arun Sori 83e46555dd Disable directory listing for Hugo file server
Fix #1400
2015-10-31 09:23:30 -06:00
Anthony Fok b29ca44c6e Show both baseURL and bind address in hugo server output
Fixes #1426
2015-09-15 23:12:01 -06:00
Scott C Wilson c00a1fcb7f Add a check for the setting of watch flag in config file
Fixes #1074
2015-07-20 14:20:07 +02:00
bep bef0f281d1 Make sure that complete server URL is logged on startup
Fixes #1113
2015-05-09 08:03:06 +02:00
Liam Bowen 2bfa9fb72b Make server bind interface configurable.
Bind by default to 127.0.0.1. Previously it always bound to all interfaces.

Always have log message display that the server is available on the
interface to which it is bound, instead of the baseUrl.

Fixes #1097
2015-05-07 22:04:40 +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
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
Anthony Fok 664fd99135 Change "ctrl+c" to "Ctrl+C" 2015-02-11 01:11:50 -07:00
Anthony Fok 60c6faa317 Revert "Try to fix mysterious test failures on Travis"
This reverts commit 71fe85df9b.

See https://github.com/PuerkitoBio/purell/pull/5
for the cause of the mysterious `go test -v ./...` failure.
2015-01-22 17:46:47 -07:00
bep 71fe85df9b Try to fix mysterious test failures on Travis 2015-01-23 00:36:47 +01:00
Anthony Fok 1cbdd3e59d Ensure that BaseUrl used in hugo server ends with /
Fixes #793, #799
2015-01-15 18:02:19 -07:00
Nathan Youngman c6f4b09f65 always use http scheme for localhost
fixes #758
2015-01-01 23:57:29 +01:00
Anthony Fok e3433e6afb Fix long descriptions of benchmark and serve commands 2014-12-24 04:40:48 -07:00
bep 8cb435f1f4 Fix redirect-loop for Hugo server
An extra slash was added to the path if baseUrl had a sub-directory, causing infinite redirect loop in Go's HTTP server.

Fixes #510
2014-11-01 22:49:26 -04:00
Marcelo Glezer 2b412d4ac7 fixed server reporting Web Server is available at https://localhost:1313 when server always serve http 2014-11-01 22:33:43 -04:00
spf13 141f3e19e0 Migrating Hugo to Afero for filesystem calls. 2014-11-01 11:57:29 -04:00
Mantas fb82f00f9d handle https prefixes in baseUrl 2014-10-07 17:18:45 -04:00
spf13 26e44506e9 adding memstat option to server 2014-09-22 09:45:05 -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
Kevin Burke 657e4a46e8 it's/its 2014-07-26 23:43:21 -07:00
spf13 7a8b754cad Fixed #301. LiveReload works on any port now. 2014-05-28 19:01:24 -04:00
spf13 be1ee22032 Proper integration of live reload with automatic injection 2014-05-16 17:49:27 -04:00
spf13 60ed5bda2b Live reloading is working! Still need to incorporate cleanly. 2014-05-16 11:48:59 -04:00