Detect if Nikola runs in `auto` or `serve` mode

12 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Dirk Olbrich

ungelesen,
28.09.2022, 05:08:3628.09.22
an nikola-discuss

Hey there, is there a way to detect if Nikola is running in `auto` or `serve` mode and use this variable in template files?

I would like to build some templates which aid in development and only show if I view the Nikola site locally via `nikola auto -b` or `nikola serve -b`. 

Example: the [Hugo](gohugo.io) static site generator sets a variable `Environment=development` during local builds with `hugo serve -w`. With the variable `{{ if .Site.IsServer }}` within a template I can detect if the site is running locally in server mode and decide which elements of this template are rendered within the build site.

Chris Warrick

ungelesen,
29.09.2022, 16:11:1029.09.22
an nikola-...@googlegroups.com
On Wed, 28 Sept 2022 at 11:08, 'Dirk Olbrich' via nikola-discuss
Hi,

this is not supported and won't be, because it breaks incremental
rebuilds. `nikola serve` is a fairly simple thing that just serves the
output directory. `nikola auto` runs `nikola build`, which affects the
contents of the output directory.

There are two ways you could approach this:

(1) on-the-fly HTML patching - this is something done by both commands
to remove <base> tags and inject livereload.js in auto, you could have
a custom serve command to do this.
(2) an alternate configuration file for use with `nikola auto` - but
if you forget to `nikola build` after achieving a satisfactory result
with `nikola auto`, you would either deploy the dev-only templates to
production (if you use the same output directory as in your main
conf.py), or deploy a stale version of the site (if you use different
output directories).

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Roberto Alsina

ungelesen,
29.09.2022, 19:06:4329.09.22
an Nikola—Discuss
If you really want to, you can probably peek at sys.argv in conf.py and set something in GLOBAL_CONTEXT

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nikola-discuss/CAMw%2Bj7LPDxEu-3bsar90hCxaB60j2%3D6hcWYGCquDioufk83Umw%40mail.gmail.com.

Marcelo Huerta

ungelesen,
29.09.2022, 20:57:3629.09.22
an nikola-...@googlegroups.com
Does this mean that the idea of using a conf.yaml has been abandoned? 

--
Marcelo Huerta

Dirk Olbrich

ungelesen,
30.09.2022, 06:48:5430.09.22
an nikola-discuss
Thank you,
I will play a bit with proposal 1) and see if I can mange a workable solution.

Meanwhile I'll stick with an extra dev template file, import it in base.tmpl and comment it out by hand before deploy.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten