Commit graph

14 commits

Author SHA1 Message Date
Asanka Herath 8114b9b751
Merge b5c5a8bd76 into 74ce5dc841 2024-03-29 16:54:44 +08:00
Bjørn Erik Pedersen a795acbcd8 all: Run gofumpt -l -w . 2024-01-28 23:14:09 +01:00
Asanka Herath b5c5a8bd76 Add configuration options for pandoc
Current options are:

  markup:
    pandoc:
      filters:
        - list
        - of
        - filters
      extensions:
        - list
        - of
        - extensions
      extraArgs:
        - --extra-arguments
        - --one-per-line

Generalize some Pandoc options.

Support configuring a bibliography in markup config

Anonymous Update

[pandoc] Allow page parameters to override site parameters.

This allows specifying things like this in the page frontmatter:

    ---
    title: Something
    bibliography:
      source: mybibliography.bib
    pandoc:
      filter:
        - make-diagrams.lua
    ...

These options are local to the page. Specifying the same under `markup`
in the site configuration applies those settings to all pages.

Paths (filters, bibliography, citation style) are resolved relative to
the page, site, and the `static` folder.

[pandoc] Support metadata

Support specifying Pandoc metadata in the site configuration and page
configuration using the following syntax:

Site (in `config.yaml`):

    ```yaml
    markup:
        pandoc:
                metadata:
                        link-citations: true
    ```

Or in frontmatter:

    ```yaml
    ---
    pandoc:
        metadata:
                link-citations: true
    ...
    ```

[pandoc] Simplify path management.

No need for any fancy path lookup gymnastics. `pandoc`'s
`--resource-path` option does the legwork of locating resources on
multiple directories.

[pandoc] Don't use x != "" to denote failure.
2023-09-13 15:24:21 -04:00
Asanka Herath c9e679075f Add configuration options for pandoc
Current options are:

  markup:
    pandoc:
      filters:
        - list
        - of
        - filters
      extensions:
        - list
        - of
        - extensions
      extraArgs:
        - --extra-arguments
        - --one-per-line

Generalize some Pandoc options.

Support configuring a bibliography in markup config

Anonymous Update

[pandoc] Allow page parameters to override site parameters.

This allows specifying things like this in the page frontmatter:

    ---
    title: Something
    bibliography:
      source: mybibliography.bib
    pandoc:
      filter:
        - make-diagrams.lua
    ...

These options are local to the page. Specifying the same under `markup`
in the site configuration applies those settings to all pages.

Paths (filters, bibliography, citation style) are resolved relative to
the page, site, and the `static` folder.

[pandoc] Support metadata

Support specifying Pandoc metadata in the site configuration and page
configuration using the following syntax:

Site (in `config.yaml`):

    ```yaml
    markup:
        pandoc:
                metadata:
                        link-citations: true
    ```

Or in frontmatter:

    ```yaml
    ---
    pandoc:
        metadata:
                link-citations: true
    ...
    ```

[pandoc] Simplify path management.

No need for any fancy path lookup gymnastics. `pandoc`'s
`--resource-path` option does the legwork of locating resources on
multiple directories.

[pandoc] Don't use x != "" to denote failure.
2023-09-13 12:54:33 -04:00
Bjørn Erik Pedersen 241b21b0fd Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
2023-05-16 18:01:29 +02:00
Bjørn Erik Pedersen 271318ad78 Split parse and render for Goldmark
This also speeds up situations where you only need the fragments/toc and not the rendered content, e.g. Related
with fragments type indexing:

```bash

name            old time/op    new time/op    delta
RelatedSite-10    12.3ms ± 2%    10.7ms ± 1%  -12.95%  (p=0.029 n=4+4)

name            old alloc/op   new alloc/op   delta
RelatedSite-10    38.6MB ± 0%    38.2MB ± 0%   -1.08%  (p=0.029 n=4+4)

name            old allocs/op  new allocs/op  delta
RelatedSite-10      117k ± 0%      115k ± 0%   -1.36%  (p=0.029 n=4+4)
```

Fixes #10750
2023-02-24 10:40:06 +01:00
Bjørn Erik Pedersen f4389e48ce
Add some basic security policies with sensible defaults
This ommmit contains some security hardening measures for the Hugo build runtime.

There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers".

For `asciidoctor` and some others we use Go's `os/exec` package to start a new process.

These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off.

You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do.

The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all.

```toml
[security]
  enableInlineShortcodes = false
  [security.exec]
    allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']
    osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$']

  [security.funcs]
    getenv = ['^HUGO_']

  [security.http]
    methods = ['(?i)GET|POST']
    urls = ['.*']
```
2021-12-16 09:40:22 +01:00
Bjørn Erik Pedersen cea1574023
Add Dart Sass support
But note that the Dart Sass Embedded Protocol is still in beta (beta 5), a main release scheduled for Q1 2021.

Fixes #7380
Fixes #8102
2020-12-30 17:32:25 +01:00
Bjørn Erik Pedersen 10ae7c3210
Improve LookPath 2020-12-19 17:03:07 +01:00
Bjørn Erik Pedersen d90e37e0c6 all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
2020-12-03 13:12:58 +01:00
Bjørn Erik Pedersen fdfa4a5fe6 Allow getJSON errors to be ignored
This change is mostly motivated to get a more stable CI build (we're building the Hugo site there, with Instagram and Twitter shortcodes sometimes failing).

Fixes #7866
2020-10-22 09:09:29 +02:00
Bjørn Erik Pedersen e625088ef5
Add render template hooks for links and images
This commit also

* revises the change detection for templates used by content files in server mode.
* Adds a Page.RenderString method

Fixes #6545
Fixes #4663
Closes #6043
2019-12-18 11:44:40 +01:00
Bjørn Erik Pedersen bfb9613a14
Add Goldmark as the new default markdown handler
This commit adds the fast and CommonMark compliant Goldmark as the new default markdown handler in Hugo.

If you want to continue using BlackFriday as the default for md/markdown extensions, you can use this configuration:

```toml
[markup]
defaultMarkdownHandler="blackfriday"
```

Fixes #5963
Fixes #1778
Fixes #6355
2019-11-23 14:12:24 +01:00
Bjørn Erik Pedersen 5f6b6ec689
Prepare for Goldmark
This commmit prepares for the addition of Goldmark as the new Markdown renderer in Hugo.

This introduces a new `markup` package with some common interfaces and each implementation in its own package.

See #5963
2019-11-06 19:09:08 +01:00