Commit graph

134 commits

Author SHA1 Message Date
Bjørn Erik Pedersen
c825a73121 Support open "current content page" in browser
This commit adds a new `--navigateToChanged` and config setting with the same name, that, when running the Hugo server with live reload enabled, will navigate to the current content file's URL on save. 

This is really useful for site-wide content changes (copyedits etc.).
Fixes #3643
2017-06-26 21:34:16 +02:00
Bjørn Erik Pedersen
873a6f1885 Run gofmt to get imports in line vs gohugoio/hugo 2017-06-13 19:12:10 +02:00
Bjørn Erik Pedersen
d8717cd4c7 all: Update import paths to gohugoio/hugo 2017-06-13 18:42:45 +02:00
Albert Nigmatzianov
421a46947a cmd: Replace flagChanged with pflag.FlagSet.Changed 2017-05-24 10:51:51 +02:00
Bjørn Erik Pedersen
a883948c4f Register all media types when in server mode
Fixes #3274
2017-04-04 18:05:19 +02:00
Bjørn Erik Pedersen
15b64d51da all: Propagate baseURL error to the callers 2017-03-27 15:43:56 +02:00
bogem
c7535b9c25 commands: Remove flagChanged from commandeer 2017-02-21 15:08:45 +01:00
Bjørn Erik Pedersen
93ca7c9e95 all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.

Updates #2701
Fixes #3016
2017-02-17 17:15:26 +01:00
Bjørn Erik Pedersen
c71e1b106e all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
2017-02-04 11:37:25 +07:00
Bjørn Erik Pedersen
92ba7219dc commands: Fix newly broken server flag handling 2017-01-11 18:54:27 +01:00
Bjørn Erik Pedersen
45e3ed517a all: Refactor to non-global logger
Note that this looks like overkill for just the logger, and that is correct,
but this will make sense once we start with the template handling etc.

Updates #2701
2017-01-07 17:06:35 +01:00
bogem
120f6b0cf2 all: Use jww instead of fmt for printing
This is an attempt to unify method for printing.
2016-11-22 22:06:48 +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
Jeremy Brown
d7f364c27e Fix for meminterval not using specified interval
Hugo seems to ignore the meminterval I specify and always uses it's default of 100ms.
This seems to be because Hugo tries to take the meminterval from the command line
(an Int) and converts it to a String and passes it to time.ParseDuration. If you pass a
different meminterval (such as `1000` as above) it will fail (time.ParseDuration requires
some units) and use the default instead.

Changed `meminterval` to be a String and added better documentation for valid time units.

Resolves: #2325
2016-08-02 19:48:07 +02:00
Cameron Moore
ca6b26fe65 commands: Allow schema-less baseURL on command line
Fixes #1632
2016-06-29 23:08:55 -06:00
Hanchen Wang
c52bb4efbe commands: Specify os port generic errors
Closes #2217
2016-06-16 15:28:06 +02:00
Bjørn Erik Pedersen
aa690c8e95 commands: Fix charsets in mimetypes
Fixes #2218
2016-06-15 19:34:21 +02:00
Bjørn Erik Pedersen
2b02a402a0 commands: Sett mime type for CSS in Hugo server
Fixes #2104
2016-04-27 21:40:35 +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
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
spf13
296d218e67 Better handling of when the specified port is already in use 2014-05-15 17:41:03 -04:00
Dato Simó
0053be979a Correctly print server URL when base-url is specified in the command line
When running hugo server like:

    $ hugo server -s docs -b myhostname

the printed output now directs to http://myhostname:1313 instead of
(invariably) http://localhost:1313.

As per server(), BaseUrl is never empty, and the required value is always
found in Viper.
2014-05-09 23:27:21 -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
Tibor Vass
6dd2e9a49a gofmt all go code 2014-01-29 18:03:35 -05:00
Vincent Batoufflet
ff9f6e1b2a Fix panic with HTTP serve initialization problems. 2014-01-28 23:44:43 -05:00
Krisztián Szabó
5550c4148e Added append-port flag 2013-12-28 22:01:36 -05:00
William King
e5aa08ff0c If baseurl is set then print that on the command line, else leave as default of localhost
Conflicts:
	commands/server.go
2013-12-28 14:02:10 -05:00
Matt Way
1abc2f0b86 properly use non-localhost BaseUrl in server command 2013-12-16 17:39:59 -05:00
spf13
b580a25d1f Better error handling when rendering error found when in watch mode
In watch mode it should continue to watch for changes, in any other mode it should exit with a -1 error code so can check for success when scripting
2013-10-25 18:03:14 -04:00
spf13
0318f7c149 Clean up server & build site logic. Fixed #94 2013-10-09 18:53:46 -04:00
spf13
e6ace71fec server command now builds prior to serving 2013-10-09 18:24:40 -04:00
spf13
be7ba0e98f server defaults to localhost unless overridden by command line flags 2013-10-04 16:03:13 -04:00
spf13
18f2b82658 Switching to the rjson library which is more friendly to human generated json. 2013-10-01 22:45:24 -04:00
spf13
3ae8dda203 Restoring build and watch functionality 2013-09-30 22:38:32 -04:00
spf13
94d7fe52f8 Change the interface to use commands and flags instead of just flags.
Better organization of main (controller style) code.
2013-09-29 02:10:29 -04:00