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

Reduce redundancy in the front-matter of markdown pages #22

Open
robyngit opened this issue May 26, 2021 · 4 comments
Open

Reduce redundancy in the front-matter of markdown pages #22

robyngit opened this issue May 26, 2021 · 4 comments

Comments

@robyngit
Copy link
Member

Update the layouts so that the markdown front-matter doesn't require repeated information. For example, change:

---
title: "Contact"
name: "Contact"
card_image: "/images/methodology/resilience/card.jpg"
bg_image: "/images/methodology/resilience/banner.jpg"
---

to

---
title: "Contact"
image: "/images/methodology/resilience/card.jpg"
---
@ThomasThelen
Copy link
Member

One note about this is that there needs to be a distinction between the name on the card and the name on the page's banner. In #10 there was the comment about including Goal: in the goal layout. The subgoals need to have Sub-Goal in the header and they use the same layout as each Goal (which would have Goal:). One solution is to have two layouts-one for goal pages and one for sub-goals, but that seems a little extreme for just a small text change. Requiring it in the front matter also seems a little excessive.

One pro that I see with keeping it in the front matter is that the pages can now use the default layout since the text isn't hardcoded in the layout.

@robyngit
Copy link
Member Author

I see what you're saying. Another possibility to consider: prepend the "Goal" or "Sub-Goal" text to the title conditionally.

I have not tested this, but as an example:

{{ $goalDir := "goals" }}
{{ $pageTitle := .Params.title }}
{{ $prefix := "" }}

{{ if eq .Section $goalDir }}
  {{ if eq .CurrentSection $goalDir }}
    {{ $prefix = "Goals" }}
  {{ else }}
    {{ $prefix = "Sub-Goals" }}
  {{ end }}
{{ end }}
{{ with $prefix }}
  {{ $pageTitle = printf "%s : %s" $prefix $pageTitle }}
{{ end }}

<h1>{{- $pageTitle -}}</h1>

See: Section variables

@ThomasThelen
Copy link
Member

ThomasThelen commented Jun 16, 2021

This kind of machinery kind of scares me because

  1. It's a lot of work for very little gain
  2. It's going to be complicated to refactor
  3. The rigidity of it will make it difficult to customize
  4. The 'title' line is easy to understand and is minimal overhead on the developer. Worst case scenario is a copy+paste operation (It's only Semi-DRY, but at the benefit of ease of refactoring/less complicated code)

Are you fairly set on getting rid of the 'title' line? If so I'll go ahead and make the change-but I have the reservations above

@robyngit
Copy link
Member Author

Yes, these are good points. Another idea:

markdown:

---
title_prefix: "Sub-Goal"
title: "Habitat"
image: "/images/methodology/goals/biodiversity/card.jpg"
---

template:

{{ $pageTitle := .Params.title }}

{{ with .Params.title_prefix }}
  {{ $pageTitle = printf "%s : %s" . $pageTitle }}
{{ end }}

<h1>{{- $pageTitle -}}</h1>

Not exactly DRY because title_prefix: "Sub-Goal" and title_prefix: "Goal" will be repeated through out the markdown content, but far less repetitive than requiring identical names and titles for all of the non-goal pages. Bonus is that content editors can easily add a title prefix to any new content types in the future.

@ThomasThelen ThomasThelen removed their assignment Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants