Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] build time interpolation of front matter in markdown / HTML (interpolate frontmatter) #871

Closed
1 of 9 tasks
thescientist13 opened this issue Jan 26, 2022 · 0 comments · Fixed by #872 or #868
Closed
1 of 9 tasks
Assignees
Labels
alpha.1 CLI discussion tied to an ongoing discussion or meeting notes documentation Greenwood specific docs feature New feature or request RFC Proposal and changes to workflows, architecture, APIs, etc SSR v0.23.0
Milestone

Comments

@thescientist13
Copy link
Member

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

At the risk of implementing / using a custom templating system (e.g. handlebars, nunjucks, etc), which is something Greenwood strives to avoid, but still recognizing that requiring JavaScript though graph.json even for static content, like what we support in frontmatter, can be a bit cumbersome.

---
template: 'post'
title: 'Git Explorer'
emoji: '💡'
date: '04.07.2020'
description: 'Local git repository viewer'
image: '/assets/blog-post-images/git.png'
---

For example, think about just trying to get that description or title into a <meta> tag. It requires JavaScript. This IMO is one key "lagging" / missing workflows Greenwood doesn't really have a good answer for. For reference

This is why most tools reach for something like handbars.

Also, taking into consideration the spirit of this discussion on keeping content out of configuration, providing a familiar mechanism to a minumum static templating could be a really quick win so user's don't have to rely on JavaScript + prerendering for simple things.

Details

At its simplest, given the frontmatter example from before

---
template: 'post'
title: 'Git Explorer'
emoji: '💡'
date: '04.07.2020'
description: 'Local git repository viewer'
image: '/assets/blog-post-images/git.png'
---

A user could access this frontmatter data in their markdown our HTML on a per page instance following the convention of JavaScript template literals and Greenwood can interpolate them at build time.

const name = 'World';

alert(`Hello ${name}!`);

Markdown

This would an example of using it in markdown file

# My Blog Post

<img src="${globalThis.page.image}" alt="Banner image for ${globalThis.page.description}">

Lorum Ipsum.

Template

<html>
  <head>
    <title>My Blog - ${globalThis.page.title}</title>
    <meta property="og:title" content="My Blog">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://www.myblog.dev">
    <meta property="og:image" content="https://www.myblog.dev/${globalThis.page.image}">
    <meta property="og:description" content="My Blog - ${globalThis.page.description}">
  </head>
  <body>
    <content-outlet></content-outlet>
  </body>
</html>

Namespacing everything with page since as part of SSR hydration, we may want attach compilation data to globalThis as well.

Requirements

  1. Make a config option called interpolateFrontmatter to enable this feature (and implement)
  2. Deprecate title and meta in greenwood.config.js
  3. Add documentation and deprecate existing meta / title APIs
  4. Add / update specs
@thescientist13 thescientist13 added RFC Proposal and changes to workflows, architecture, APIs, etc CLI SSR feature New feature or request labels Jan 26, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Jan 26, 2022
@thescientist13 thescientist13 self-assigned this Jan 26, 2022
@thescientist13 thescientist13 added documentation Greenwood specific docs discussion tied to an ongoing discussion or meeting notes labels Jan 26, 2022
@thescientist13 thescientist13 moved this from TODO to IN PROGRESS in 7 - SSR and External Data Sources Jan 28, 2022
@thescientist13 thescientist13 moved this from IN PROGRESS to IN REVIEW in 7 - SSR and External Data Sources Jan 28, 2022
This was linked to pull requests Feb 5, 2022
@thescientist13 thescientist13 moved this from IN REVIEW to DONE in 7 - SSR and External Data Sources Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.1 CLI discussion tied to an ongoing discussion or meeting notes documentation Greenwood specific docs feature New feature or request RFC Proposal and changes to workflows, architecture, APIs, etc SSR v0.23.0
Projects
No open projects
1 participant