sc0ttj / mdsh

A simple static site generator, using Markdown and Bash
https://sc0ttj.github.io/mdsh/
10 stars 0 forks source link

Custom taxonomies #92

Open sc0ttj opened 4 years ago

sc0ttj commented 4 years ago

Problem(s):

  1. Currently, pages and posts can only be categorised and indexed using these taxonomies:

Therefore the only index pages generated are for authors, categories and tags.

Users should be able to define their own taxonomies, and therefore, index pages

  1. Pages and posts are currently not really separate things...
  1. Current index pages (lists of posts) occupy root of site

Solution to last two points:

We can work out the page type by checking the (soon to be created) page_type field in the front matter, and grabbing the relevant data.. This could be a YAML file called page_types.yml, containing:

page:
  name: page
  taxonomies: author, category, tags
post:
  name: post
  taxonomies: author, category, tags
event: 
  name: event
  taxonomies: organiser, category, genre, location, start_date, end_date, tags
product:
  name: product
  taxonomies: brand, category, seller, tags

(Note: product options like price should not get an index page, so still live in site.yml)

When users do new event or new product, we set $1 to page_type, check it exists in page_types, and if so, we grab the relevant taxonomy list, and generate the front matter as usual (wizard style, in the terminal).


About Taxonomies

Let’s assume you are making a website about movies. You may want to include the following taxonomies:

Actors
Directors
Studios
Genre
Year
Awards

You'd specify the values of these items in the front matter of each .mdsh file.

From these terms, Mdsh would automatically create index pages for each taxonomy - actors, directors, studios, genres, years, and awards - with each index page listing all of the Movies that matched that specific taxonomy.

See: https://gohugo.io/content-management/taxonomies/


Current taxonomy not defined anywhere, but is basically this:

taxonomies:
  category: categories
  tag: tags

How to

Custom taxonomies other than the defaults must be defined in your site config before they can be used throughout the site.

You need to provide both the plural and singular labels for each taxonomy.

taxonomies:
  category: categories
+  series: series
  tag: tags

Once a taxonomy is defined at the site level, any piece of content can be assigned to it

Assigning content to a taxonomy is done in the front matter. Simply create a variable with the plural name of the taxonomy and assign all terms you want to apply to the instance of the content type.

title: Some cool title
categories:
  - Development
series:
  - Go Web Dev
slug: hugo
tags:
  - Development
  - Blogging

If you need to add custom metadata to your taxonomy terms, create a page for that term at /assets/data/<TAXONOMY>/<TERM>/_index.md and add your metadata in it’s front matter.

Continuing with our ‘Actors’ example, let’s say you want to add a wikipedia page link to each actor. Your terms pages would be something like this:

  ---
  title: "Bruce Willis"
  wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
  ---

There are multiple ways to use taxonomies throughout your project templates:


About "Archetypes" (page types)

Archetypes are templates used when creating new content.

What are Archetypes?

Archetypes are markdown template files in the .app/templates/markdown/ directory, that contain pre-configured front matter.

new page "My cool page"

^ where $1 is the archetype name, and $2 the title of the new item to be created.

The above would create a new content file in using the first archetype file found:

    .app/templates/markdown/page.md
    .app/templates/markdown/post.md

Users could also run something like this:

new movie "The Haunted House (2019)"

The user should be asked to enter each item in the front matter, in the usual wizard-style way (fill out each field on the terminal).

The movie.md template could contain front matter which, when given the right data, would like so:

title:                  The Haunted House (2019)
slug:                  the-haunted-house-2019
release_date:  2019
publisher:         Fox
director:            Tony Bobsonsonon
actors:
  - Mr. Foo man
  - Mrs. Bar woman
---