diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..19df328c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +html/ diff --git a/.vuepress/README.md b/.vuepress/README.md new file mode 100644 index 00000000..7c43bff1 --- /dev/null +++ b/.vuepress/README.md @@ -0,0 +1,11 @@ +--- +editLink: false +--- + +# IPLD Specifications + +Specifications for the Inter-planetary Linked Data (IPLD) project: + +* **[IPLD Schemas](./schemas/)** + +See more or contribute on [GitHub](https://github.com/ipld/specs/). \ No newline at end of file diff --git a/.vuepress/config.js b/.vuepress/config.js new file mode 100644 index 00000000..559ce184 --- /dev/null +++ b/.vuepress/config.js @@ -0,0 +1,55 @@ +require('./highlight') + +function linkfix (md) { + const defaultRender = md.renderer.rules.link_open + + md.renderer.rules.link_open = function (tokens, idx, options, env, self) { + const hrefIndex = tokens[idx].attrIndex('href'); + if (hrefIndex > -1) { + const href = tokens[idx].attrs[hrefIndex][1] + if (/\.(ipldsch|json)$/.test(href)) { + tokens[idx].attrs[hrefIndex][1] = `${href}.md` + } + } + + return defaultRender(tokens, idx, options, env, self) + } +} + +module.exports = { + title: 'IPLD Specifications', + description: 'Specifications for the Inter-planetary Linked Data project', + base: '/specs/', + themeConfig: { + repo: 'ipld/specs', + editLinks: true, + editLinkText: 'Edit this page on GitHub', + lastUpdated: 'Last Updated', + smoothScroll: true, + nav: [ + { text: 'Home', link: '/' }, + { text: 'IPLD Schemas', link: '/schemas/' } + ], + sidebar: { + '/schemas/': [{ + title: 'IPLD Schemas', + collapsable: false, + sidebarDepth: 2, + children: [ + ['goals', 'Goals'], + ['feature-summary', 'Feature Summary'], + ['introduction', 'Introduction'], + ['authoring-guide', 'Authoring Guide'], + 'links', + 'schema-kinds', + ['representations', 'Representations'], + ['advanced-layouts', 'Advanced Layouts'] + ] + }] + } + }, + extendMarkdown: md => { + // use more markdown-it plugins! + md.use(linkfix) + } +} diff --git a/.vuepress/highlight.js b/.vuepress/highlight.js new file mode 100644 index 00000000..75b762d9 --- /dev/null +++ b/.vuepress/highlight.js @@ -0,0 +1,36 @@ +// this require is awkward but technically the proper way to find the 'prismjs' +// that's used by vuepress -> @vuepress/markdown -> prismjs +const prism = require( + require.resolve('prismjs', + require.resolve('@vuepress/markdown', + require.resolve('vuepress')))) + +prism.languages.ipldsch = { + typedef: { + pattern: /^[ \t]*(?:type|advanced)[ \t][A-Z](_?[A-Za-z0-9])*\b/m, + inside: { + keyword: /^[ \t]*(type|advanced)/m, + 'class-name': /[\w]+$/ + } + }, + keyword: /\b(?:bool|int|float|string|bytes|null|nullable|optional)\b/, + builtin: /\b(struct|union|enum)(?=[ \t]*\{)\b/, + representation: { + pattern: /^}[ \t]representation\b/m, + inside: { + builtin: /representation/ + } + }, + operator: /=/, + number: /\b-?\d+\.?\d*(?:e[+-]?\d+)?\b/i, + punctuation: /[(){}:[\]\|&]/, + string: { + pattern: /(")(?:\\[\s\S]|(?!\1)[^\\])*\1/, + greedy: true + }, + comment: { + pattern: /(^|[^"])#.*/, + lookbehind: true, + greedy: true + } +} diff --git a/.vuepress/styles/index.styl b/.vuepress/styles/index.styl new file mode 100644 index 00000000..e2224669 --- /dev/null +++ b/.vuepress/styles/index.styl @@ -0,0 +1,3 @@ +div[class~="language-ipldsch"]::before { + content: "ipld schema"; +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..3870ea01 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "scripts": { + "prepare:base": "rm -rf html && mkdir html && cp -a .vuepress/ html/.vuepress/ && mv html/.vuepress/README.md html/", + "prepare:content": "cp -a schemas/ html/schemas/", + "prepare:ipldsch": "cd html && find . -name \\*.ipldsch -exec sh -c \"echo '---\\neditLink: false\\n---\\n\\n\\`\\`\\`ipldsch' > {}.md && cat {} >> {}.md && echo '\\`\\`\\`' >> {}.md\" \\;", + "prepare:json": "find html/ -name \\*.json -exec sh -c \"echo '---\\neditLink: false\\n---\\n\\n\\`\\`\\`json' > {}.md && cat {} >> {}.md && echo '\\`\\`\\`' >> {}.md\" \\;", + "build:vue": "vuepress build html --no-cache", + "build": "set -e; for t in prepare:base prepare:content prepare:ipldsch prepare:json build:vue; do npm run $t; done" + }, + "dependencies": { + "vuepress": "^1.2.0" + } +} diff --git a/schemas/authoring-guide.md b/schemas/authoring-guide.md index 0f36debc..8c4dca6b 100644 --- a/schemas/authoring-guide.md +++ b/schemas/authoring-guide.md @@ -819,7 +819,7 @@ IPLD Schemas are intended to serve a documentation role as well as a programmati When embedding IPLD Schema declarations in Markdown, use code blocks with the language marker `ipldsch`, i.e.: -
+

 ```ipldsch
 type Foo struct {
   a   Int
@@ -829,7 +829,7 @@ type Foo struct {
 
 type Message string
 ```
-
+
Any such block found in a Markdown document will be extracted and stitched together to form a single Schema document. diff --git a/schemas/schema-kinds.md b/schemas/schema-kinds.md index 316a21c3..7750f2d3 100644 --- a/schemas/schema-kinds.md +++ b/schemas/schema-kinds.md @@ -233,11 +233,15 @@ expose and correctly preserve the value's presense or absence. -
+
+
+```ipldsch
 type Foo struct {
 	bar Bool
 }
-
+``` + + {"bar": true}
{"bar": false}
@@ -247,11 +251,15 @@ type Foo struct { -
+
+
+```ipldsch
 type Foo struct {
 	bar nullable Bool
 }
-
+``` + + {"bar": true}
{"bar": false}
@@ -262,11 +270,15 @@ type Foo struct { -
+
+
+```ipldsch
 type Foo struct {
 	bar optional Bool
 }
-
+``` + + {"bar": true}
{"bar": false}
@@ -277,11 +289,15 @@ type Foo struct { -
+
+
+```ipldsch
 type Foo struct {
 	bar optional nullable Bool
 }
-
+``` + + {"bar": true}
{"bar": false}
@@ -293,13 +309,17 @@ type Foo struct { -
+
+
+```ipldsch
 type Foo struct {
 	bar Bool
 } representation map {
 	field bar default "false"
 }
-
+``` + + {"bar": true}
{}