Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
www: add vuepress for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Nov 13, 2019
1 parent a029164 commit d091f19
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
html/
11 changes: 11 additions & 0 deletions .vuepress/README.md
Original file line number Diff line number Diff line change
@@ -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/).
55 changes: 55 additions & 0 deletions .vuepress/config.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
36 changes: 36 additions & 0 deletions .vuepress/highlight.js
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions .vuepress/styles/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div[class~="language-ipldsch"]::before {
content: "ipld schema";
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions schemas/authoring-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.:

<pre>
<pre class="language-markdown"><code>
```ipldsch
type Foo struct {
a Int
Expand All @@ -829,7 +829,7 @@ type Foo struct {

type Message string
```
</pre>
</code></pre>

Any such block found in a Markdown document will be extracted and stitched together to form a single Schema document.

Expand Down
40 changes: 30 additions & 10 deletions schemas/schema-kinds.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,15 @@ expose and correctly preserve the value's presense or absence.
</tr>

<tr>
<td width=40%><pre>
<td width=40%>

```ipldsch
type Foo struct {
bar Bool
}
</pre></td>
```

</td>
<td width=20%>
<code>{"bar": true}</code><br>
<code>{"bar": false}</code><br>
Expand All @@ -247,11 +251,15 @@ type Foo struct {
</tr>

<tr>
<td><pre>
<td>

```ipldsch
type Foo struct {
bar nullable Bool
}
</pre></td>
```

</td>
<td>
<code>{"bar": true}</code><br>
<code>{"bar": false}</code><br>
Expand All @@ -262,11 +270,15 @@ type Foo struct {
</tr>

<tr>
<td><pre>
<td>

```ipldsch
type Foo struct {
bar optional Bool
}
</pre></td>
```

</td>
<td>
<code>{"bar": true}</code><br>
<code>{"bar": false}</code><br>
Expand All @@ -277,11 +289,15 @@ type Foo struct {
</tr>

<tr>
<td><pre>
<td>

```ipldsch
type Foo struct {
bar optional nullable Bool
}
</pre></td>
```

</td>
<td>
<code>{"bar": true}</code><br>
<code>{"bar": false}</code><br>
Expand All @@ -293,13 +309,17 @@ type Foo struct {
</tr>

<tr>
<td><pre>
<td>

```ipldsch
type Foo struct {
bar Bool
} representation map {
field bar default "false"
}
</pre></td>
```

</td>
<td>
<code>{"bar": true}</code><br>
<code>{}</code><br>
Expand Down

0 comments on commit d091f19

Please sign in to comment.