diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 86a0de7..ef8a73a 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -33,8 +33,12 @@ jobs: run: | curl -L -s https://unpkg.com/wq > docs/js/wq.js curl -L -s https://unpkg.com/@wq/markdown@latest > docs/js/markdown.js + curl -L -s https://unpkg.com/@wq/analyst@latest > docs/js/analyst.js + curl -L -s https://unpkg.com/@wq/chart@next > docs/js/chart.js sed -i "s/^import\(.*\)https:\/\/unpkg.com\/wq/import\1.\/wq.js/" docs/js/*.js sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/markdown@next/import\1.\/markdown.js/" docs/js/*.js + sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/analyst/import\1.\/analyst.js/" docs/js/*.js + sed -i "s/^import\(.*\)https:\/\/unpkg.com\/@wq\/chart/import\1.\/chart.js/" docs/js/*.js - name: Build with Jekyll uses: actions/jekyll-build-pages@v1 with: diff --git a/docs/index.md b/docs/index.md index 57424a0..ff72c05 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,6 +16,15 @@ wq_config: [**Django REST Pandas on GitHub**](https://github.com/wq/django-rest-pandas) +### Demo + +```js +// @wq/analyst +{ + "test": 1 +} +``` + [pandas]: https://pandas.pydata.org/ [Django REST Framework]: https://www.django-rest-framework.org/ [formats]: ./renderers/index.md diff --git a/docs/js/$index.js b/docs/js/$index.js index 827ba40..a8a4715 100644 --- a/docs/js/$index.js +++ b/docs/js/$index.js @@ -3,11 +3,14 @@ layout: null --- import wq, { modules } from 'https://unpkg.com/wq'; -import markdown, { renderers } from 'https://unpkg.com/@wq/markdown@next'; +import markdown, { components } from 'https://unpkg.com/@wq/markdown@next'; +import Demo from './demo.js'; const React = modules['react']; const { Typography, Link } = modules['@wq/material']; +components.code = Demo; + wq.use(markdown); const config = { diff --git a/docs/js/demo.js b/docs/js/demo.js new file mode 100644 index 0000000..1e01d3b --- /dev/null +++ b/docs/js/demo.js @@ -0,0 +1,31 @@ +import { modules } from "https://unpkg.com/wq"; +import { components } from "https://unpkg.com/@wq/markdown"; +import { Analyst } from "https://unpkg.com/@wq/analyst"; + +const React = modules.react; +const Code = components.code; + +export default function CodeDetect(props) { + const { children: value } = props; + if (value.includes("// @wq/analyst")) { + const config = parseConfig(value); + if (config) { + return React.createElement(Analyst, { config }); + } else { + return React.createElement(Code, { + children: "// Error parsing @wq/analyst config\n\n" + value, + }); + } + } else { + return React.createElement(Code, props); + } +} + +function parseConfig(value) { + value = value.replace("// @wq/analyst", "").trim(); + try { + return JSON.parse(value); + } catch { + return null; + } +}