lexify

1.0.5 • Public • Published

lexify

Converts lexicon md files to HTML and JSONLD. Lexicon md files are compact format definition lists and the generated HTML will include RDFa microformatting and the JSONLD will be valid based on specs from schema.org.

Usage

lexify is intended to be run via npx in a properly prepared directory.

npx lexify [src] [dest] [template]

[src] is a directory or markdown file. If a directory is passed all md files in the directory will be parsed (default ./src)

[dest] is a destination directory (default ./docs)

[template] is the mustache template for the HTML page (default ./template/lexicon.mustache)

Everything in the dest folder is generated by lexify, just make sure the folder exists.

A properly formatted src file is a compact format definition list with one term per line. You can add HTML into either the term or definition. It has a markdown extension so that it is nice and readable in github, but it's really just HTML. Here is a properly formatted src file:

<dl>Baseball Pitching Terms
<dt><a href="https://authoritativeSource.com">Fastball</a><dd>A pitch thrown at or near maximum speed
<dt>Change Up<dd>A pitch that mimics a fastball's mechanics, but is held deeper in the hand so that it arrives more slowly and throws off the batters timing.
<dt>Curve Ball<dd>A pitch thrown with forward rotation that causes it to dive before reaching the batter.

lexify uses the Mustache templating language. Since Mustache is "logic-less" we can't just pass in the json-ld as the view (Boo!). We have to pass in a view that fits the following format. Don't worry, this is done behind the scenes, it's provided here as a reference for your own Mustache template:

lexica: [
  {
    termset: [{
      "@type":[String],
      "@id":String,
      "name":String
    }],
    terms: [{
      "@type": String,
      "@id": String,
      "name": String,
      "description": String,
      "inDefinedTermSet": String
    },
    ...
    ]
  }
]

If there are multiple lexicon markdown files, they will be concatentated into one view and passed to the Mustache template as additional elements in the lexica array.

You will need a template/lexicon.mustache file that is used to render the HTML. Here's a starting point, but feel free to make it yours:

<h1>My Awesome List of Terms</h1>
 
{{#lexica}}
  <dl vocab="http://schema.org/">
  {{#termset}}
    <div typeof="{{@type}}">
      <h2>
        <a property="itemid" href="{{& @id}}"><span property="name">{{name}}</span></a>
      </h2>
    </div>
  {{/termset}}
  {{#terms}}
    <div typeof="DefinedTerm">
      <link property="url" href="{{& @id}}"/>
      <dt property="name">{{name}}</dt>
      <dd property="description">{{description}}</dd>
      <link property="inDefinedTermSet" href="{{#termset}}{{& @id}}{{/termset}}" />
    </div>
  {{/terms}}
  </dl>
{{/lexica}}

Readme

Keywords

none

Package Sidebar

Install

npm i lexify

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

14.5 kB

Total Files

9

Last publish

Collaborators

  • dtex