Sign in

YAML-Headers

  • This topic has 7 replies, 2 voices, and was last updated 7 months, 1 week ago by .
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #5565
    tiptronic
    I keep my local documents mostly in Markdown format (.md), where I use YAML-Headers to specify meta-data.
    Is there a way to keep these headers in a (markdown-) post and possibly also use these headers to create tags?
    If not: are there plans to do that? (If not, I might volunteer to add those helpers…)
    ---
    title: Snippets
    path: /snippets
    date: 2061-01-01
    summary: snippets to remember
    categories: [Development]
    tags: ["development", "javascript"]
    image: images/snippets.jpg
    color: yellow
    ---
    

     

    #5638
    Jampi

    Hi @tiptronic,

    front matter options are basically post options, most you listed are already supported by default.

    <span class=”enlighter-text”>title: <span style=”color: #339966;”>covered </span></span>
    <span class=”enlighter-text”>path: <span style=”color: #339966;”>covered <span style=”color: #000000;”>(post options > SEO > Post Slug)</span></span></span>
    <span class=”enlighter-text”>date: <span style=”color: #339966;”>covered</span></span>
    <span class=”enlighter-text”>tags: </span><span class=”enlighter-g1″><span class=”enlighter-text”><span style=”color: #339966;”>covered</span></span></span>
    <span class=”enlighter-text”>image: <span style=”color: #339966;”>covered</span></span>

    I don’t think <span class=”enlighter-text”>categories can be</span><span class=”enlighter-g1″> supported (I think), I don’t know how you could add.</span>

    For the others you should create your own (https://getpublii.com/dev/post-config-options/#post-config-options) and add the variables in the template (https://getpublii.com/dev/post-config-options/#how-to-add-a-custom-optionbr).

    #5645
    tiptronic

    Hi @jampi

    thanks for the reply. It could be, we are talking about 2 different things 😉

    I want the postOptions to be created dynamically from the YAML (front-matter) keys, which are entered as raw text inside a post.

    When reading a post, the application looks for the front-matter and – if found – uses those front-matter-variables as postOptions. E.g.:

    ---
    title: Snippets
    custom1: Hello
    custom2: This is a test
    ---

    And then strips front-matter-variables from the output.

    Then – in the template – I just can use those variables as regular ‘postOptions’

    {{#if postViewConfig.post.title}}
    <h1>{{postViewConfig.post.title}}</h1>
    {{/if}}
    {{#if postViewConfig.post.custom1}}
    <h3>{{postViewConfig.post.custom1}}</h3>
    {{/if}}
    {{#if postViewConfig.post.custom2}}
    {{postViewConfig.post.custom2}}
    {{/if}}

    etc … results in this:

    <h1>Snippets</h1>
    <h3>Hello</h3>
    <p>This is a test</p>

    (front-matter always wins over built-in postOptions…)

    I hope this makes it a bit more obvious, what I’m trying to do.

    This makes it incredible powerful to create/use NoSQL-like content, and makes it also pretty easy to ‘tune’ the output by just adjusting some templates/partials….

    Does that make my intent clearer?

    (Btw: if there was a plugin API, this would also make a nifty plugin, imo)

    #5646
    Jampi

    Hi!

    Yes I understand what you said.

    You want:

    <span class=”enlighter-text”>custom1: Hello</span>
    <span class=”enlighter-text”>custom2: </span><span class=”enlighter-k1″>This</span><span class=”enlighter-text”> is a test</span>
    <span class=”enlighter-text”>—</span>
    So you can set a custom post config options like this:
    "postConfig": [
    {
    "name": "custom1",
    "label": "insert custom1 value",
    "value": "",
    "type": "text"        
    }
    {
    "name": "custom2",
    "label": "insert custom2 value",
    "value": "",
    "type": "text"        
    }
    ]

    In the post config you’ll find this input text to fill.

    To render them in the template you use:

    <h2>{{@config.post.custom1}}</h2>
    <p>{{@config.post.custom2}}</p>

    I it’s a little different than what you’d do in hugo, since the template language is different, and there’s a GUI instead of plain .md file, but the result is the same.

    If it isn’t what you mean, sorry, I can’t help 🙂

    #5647
    Jampi

    This is what you’ll see in the post options.

    (link to image)

    #5648
    tiptronic

    Thanks @jampi,

    I’ve seen that… it’s close, but unfortunately that doesn’t work for me. I want to keep front-matter with the markdown.

    I would like to have Publii take the value of the front-matter-variable and use it as value.

    "postConfig": [
    {
    "name": "custom1",
    "label": "insert custom1 value",
    "value": "use front-matter-variable 'custom1'",
    "type": "text"      
    },
    {
    "name": "custom2",
    "label": "insert custom2 value",
    "value": "use front-matter-variable 'custom2'",
    "type": "text"      
    }
    ]
    

    And – of course – then strip the front-matter alltogether before saving to HTML.

    If there will be a plugin API available at some point to process post-data I’ll re-visit this.
    Please feel free to drop me a note, if you are working on something and need some input.

    And thanks again for your input…

    btw. normally I code those things by hand and export via a shell, but Publii looks interesting and I really like what you did so far 🙂

    #5649
    Jampi

    I’m not in the Publii team, just a user trying to help a fellow Publii user 😉

    #5650
    tiptronic

    Anyway… thanks for your input!! 😉

    So, if someone from the team reads this – feel free to join the discussion 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.