IBM / marked-it-cli

marked-it-cli
MIT License
5 stars 15 forks source link

Print YAML definition metadata as toc properties #20

Closed jenschlot closed 3 years ago

jenschlot commented 3 years ago

Can we add an extension or configuration to pull in any "property" from the YAML definition at the top of the MD file, and print it as a property in the toc for that entry...?

An example would be to pull the lastupdated value in the MD files YAML definiton:

---
copyright:
  years: 2020
lastupdated: "2020-05-08"
keywords: compliance, environmental information
subcollection: overview
---

And, print as a property in the toc.json, something like:

"topics": [
            {
                "href": "overview/ibm-cloud-platform.html#whatis-platform",
                "label": "What is the IBM Cloud platform?",
                "id": "overview-whatis-platform",
                "lastupdated": "2020-05-08",
gptt916 commented 3 years ago

If this is doable, or some other alternative similar to this, could you point me in the direction in where to make the changes? I could look into working on this.

grant-g commented 3 years ago

@gptt916 The topic object is created in tocJSONadapter.js#createTopic(). It doesn't look like it has the properties handy currently, so they would need to be passed along the chain of callers if possible.

grant-g commented 3 years ago

Invocations of the json.toc.onTopic extension now include a data.frontMatterMap attribute, which enables implementors of this extension to update generated topics according to the document's front matter. For an example of doing this with a lastupdated attribute see the example/jsonTocExt.js file change in commit https://github.com/IBM/marked-it-cli/commit/d8614e628e5b10ce29a4247167a802c291dca669.

Closing Issue.