knockout / tko

🥊 Technical Knockout – The Monorepo for Knockout.js (4.0+)
http://www.tko.io
Other
274 stars 34 forks source link

Convert legacy documentation #141

Open brianmhunt opened 3 years ago

brianmhunt commented 3 years ago

Background

Knockout has a lot of documentation, much of which is application to TKO as well. It's mostly written in Markdown. I've written a little documentation in Markdown as well.

In general, Markdown is an easily accessible format for documentation, but sufficiently dynamic that we should be able to reference everything from there.

Objective

  1. Add documentation to this monorepo
  2. Deploy the documentation with an automated command to e.g. Github Pages or Firebase (both being Fastly)
  3. Create a Github Action to auto-deploy on changes

Technical discussion

Some documentation is at:

The unified, remark processor looks to be an excellent preprocessor, with a good AST generator like this:

#!/usr/bin/env node
const fs = require('fs')
const unified = require('unified')
const markdown = require('remark-parse')
const html = require('remark-html');

const markdownText = fs.readFileSync('/dev/stdin', 'utf8')

unified()
  .use(markdown)
  .use(() => tree => console.log(JSON.stringify(tree, null, 2)))
  .use(html)
  .processSync(markdownText)
  .toString();

What might make sense is to skip the AST, or even JSX, and jump right to our own JSX object representation i.e.

interface JsxObject {
   element: string // tagName
   children?: JsxObject[],
   attributes?: Record<string, string>,
}

We'd need to create our own html-like processor that generates the JSX, but we could generate .json files that we could do something trivial to load the page like this:

observable(tko.jsx.createElement(await import('./docs/doc-as-markdown.json'))