Skip to content

Commit 0d19d8b

Browse files
authored
Doc website scaffolding + fixes
Fixes: quarto preview, svelte files in subfolders, CSS
2 parents f7448e1 + 297ae5c commit 0d19d8b

22 files changed

+3259
-72
lines changed

.github/workflows/_publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
branches: main
5+
6+
name: Quarto Publish
7+
8+
jobs:
9+
build-deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Quarto
18+
uses: quarto-dev/quarto-actions/setup@v2
19+
20+
- name: Install npm
21+
uses: actions/setup-node@v3
22+
23+
- name: Install npm packages
24+
run: npm install
25+
working-directory: ./docs
26+
27+
- name: Render and Publish
28+
uses: quarto-dev/quarto-actions/publish@v2
29+
path: docs
30+
with:
31+
target: gh-pages
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414

1515
# lua
1616
/.luarc.json
17+
18+
# rendered documentation site
19+
/docs/_site/
20+
/docs/.quarto/
21+
/docs/.sverto/

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# sverto
2-
Add Svelte visualisations to your Quarto documents
32

4-
## 🛍 Prerequisites
3+
**Sverto** is an extension for [Quarto](https://quarto.org) that lets you seamlessly write and include [Svelte](https://svelte.dev) components, like charts and other visuals, in your Quarto website.
4+
5+
Your Svelte components can seamlessly react to your ObservableJS code, making it quick and easy to build visuals that animate in response to [user inputs](https://observablehq.com/@observablehq/inputs?collection=@observablehq/inputs) or other changing data in your document.
6+
7+
## 📋 Prerequisites
8+
9+
You'll need to install two things to run Sverto:
510

611
- [Quarto](https://quarto.org)
712
- [Node and the Node Package Manager (npm)](https://nodejs.org)
@@ -11,18 +16,18 @@ Add Svelte visualisations to your Quarto documents
1116
Install the project extension using:
1217

1318
```
14-
quarto use template 360-info/sverto@firstrelease
19+
quarto use template 360-info/sverto@firstrelease-docs
1520
```
1621

17-
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
18-
1922
Then run:
2023

2124
```
2225
npm install
2326
```
2427

25-
This will install everything you need for your Svelte components to work to the `node_modules` folder. You won't need to touch this folder, and it doesn't need to go into version control. It'll also create a `package-lock.json`, which you _should_ version control.
28+
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
29+
30+
> **Note:** Sverto depends on running [project pre-render scripts](https://quarto.org/docs/projects/scripts.html#pre-and-post-render), so you can't currently use it with single documents.
2631
2732
## 🎉 Use
2833

@@ -37,10 +42,10 @@ Here's the short way to add Svelte component you've written to a Quarto doc:
3742
```
3843
3944
2. Import your Svelte component with `Component = import_svelte("Component.svelte")`
40-
3. Add a target block for your visual and give it an `#id`
45+
3. Add a target block for your visual using `:::` and give it an `#id`
4146
4. Instantiate the Svelte component with `myVisual = Component.default()` using some default props and your target block
4247
5. Update the instantiated component with `myVisual.propName`
43-
6. Render your Quarto project as usual with `quarto render` or `quarto preview`.
48+
6. Render your Quarto website as usual with `quarto render` or `quarto preview`.
4449
4550
**To see this all in practice, check out [`example.qmd`](./example.qmd).**
4651
@@ -71,4 +76,4 @@ If you'd prefer to compile your own Svelte components instead of letting this ex
7176
7277
If you have any problems with the extension, please feel free to [create an issue](https://github.com/360-info/sverto)!
7378
74-
Special thanks to [Carlos Scheidegger](https://github.com/cscheid) from [Posit](https://posit.co) for his time and guidance in designing Sverto!
79+
Special thanks to [Carlos Scheidegger](https://github.com/cscheid) from [Posit](https://posit.co) for his time and guidance getting Sverto working!

_extensions/sverto/create-imports.lua

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,22 @@ local preprocess_qmd_filter = {
6666
"import%_svelte%(\"([%w;,/%?:@&=%+%$%-_%.!~%*'%(%)#]+)%.svelte\"%)"
6767

6868
local block_text = block.text
69-
70-
print(">>> OJS block found...")
71-
print(block_text)
69+
70+
-- get the qmd_path from disk
71+
local current_qmd_path = read_file(".sverto/.sverto-current-qmd-folder")
7272

7373
-- first, extract .svelte paths in import_svelte() statements
7474
for svelte_path in block_text:gmatch(svelte_import_syntax) do
75-
print("Svelte file found...")
76-
print(svelte_path)
77-
-- table.insert(svelte_files, svelte_path .. ".svelte")
78-
append_to_file(".sverto/.sverto-imports", svelte_path .. ".svelte\n")
75+
append_to_file(".sverto/.sverto-imports",
76+
current_qmd_path .. svelte_path .. ".svelte\n")
7977
end
8078

8179
-- now change `import_svelte("X.svelte")` refs to `import("X.js")`
8280
-- TODO - neaten up relative paths instead of assuming we're going from
8381
-- /site_libs/quarto-ojs
8482
block.text = block_text:gsub(
8583
svelte_import_syntax,
86-
"import(\"./../../%1.js\");")
84+
"import(\"./../../" .. current_qmd_path .. "%1.js\");")
8785

8886
end
8987
return block
@@ -117,20 +115,16 @@ end
117115
-- (write the identified .svelte files out to a file too!)
118116
for key, qmd_path in ipairs(in_files) do
119117

120-
-- print(">>> CREATING IMPORT FOR " .. qmd_path)
121118
local doc = pandoc.read(read_file(qmd_path))
119+
120+
-- store the current qmd_path on disk so the filter can access it
121+
write_file(".sverto/.sverto-current-qmd-folder", path_dir(qmd_path))
122122

123123
-- pre-process the qmd, populating `svelte_files` in the process
124124
-- local svelte_files = {}
125125
local transformed_doc = doc:walk(preprocess_qmd_filter)
126126
create_dir_recursively(".sverto/" .. path_dir(qmd_path))
127127
write_file(".sverto/" .. qmd_path, pandoc.write(transformed_doc, "markdown"))
128-
129-
-- write the svelte_files out to .sverto-imports
130-
-- svelte_file_text = table.concat(svelte_files, "\n")
131-
-- print("Saving Svelte imports:")
132-
-- print(svelte_file_text)
133-
-- write_file(".sverto/.sverto-imports", svelte_file_text)
134128

135129
end
136130

_extensions/sverto/refresh.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// delete the temporary import block files and the temp render metadata
2-
try {
3-
await Deno.remove(".sverto/", { recursive: true })
4-
} catch {
52

3+
if (Deno.env.get("QUARTO_PROJECT_RENDER_ALL") == "1") {
4+
try {
5+
await Deno.remove(".sverto/", { recursive: true })
6+
} catch {
7+
8+
}
69
}
10+
Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
11
import svelte from 'rollup-plugin-svelte';
22
import commonjs from '@rollup/plugin-commonjs';
33
import resolve from '@rollup/plugin-node-resolve';
4-
// import livereload from 'rollup-plugin-livereload';
54
import { terser } from 'rollup-plugin-terser';
6-
import css from 'rollup-plugin-css-only';
75

86
const fs = require('fs');
97
const path = require('node:path');
108

119
// this is false when we run rollup with -w/--watch (never presently)
1210
const production = !process.env.ROLLUP_WATCH;
1311

14-
// function serve() {
15-
// let server;
16-
17-
// function toExit() {
18-
// if (server) server.kill(0);
19-
// }
20-
21-
// return {
22-
// writeBundle() {
23-
// if (server) return;
24-
// server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
25-
// stdio: ['ignore', 'inherit', 'inherit'],
26-
// shell: true
27-
// });
28-
29-
// process.on('SIGTERM', toExit);
30-
// process.on('exit', toExit);
31-
// }
32-
// };
33-
// }
34-
3512
// get quarto project output directory and list of inputs
36-
// const quartoOutDir = process.env.QUARTO_PROJECT_OUTPUT_DIR;
3713
const quartoOutDir = fs.readFileSync('.sverto/.sverto-outdir', 'utf8');
3814

39-
let svelteConfig = {};
4015
const svelteImportListPath = '.sverto/.sverto-imports';
4116

4217
// skip svelte compilation if there's nothing to compile
@@ -64,27 +39,19 @@ export default uniqueSvelteFiles.map(
6439
},
6540
plugins: [
6641
svelte({
42+
// css is added to the js bundle instead
43+
emitCss: false,
6744
compilerOptions: {
45+
// required for ojs reactivity
6846
accessors: true,
6947
dev: !production,
7048
}
7149
}),
72-
css({
73-
output: path.join(
74-
quartoOutDir,
75-
path.dirname(svelteFile),
76-
path.basename(svelteFile, ".svelte") + ".css")
77-
}),
7850
resolve({
7951
browser: true,
8052
dedupe: ["svelte"]
8153
}),
8254
commonjs(),
83-
// !production && serve(),
84-
// !production && livereload("public"),
8555
production && terser()
86-
]//,
87-
// watch: {
88-
// clearScreen: false
89-
// }
56+
]
9057
}));

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.quarto/
2+
3+
/node_modules/
4+
/.sverto/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
title: Sverto
2+
author: 360info
3+
version: 0.0.1
4+
quarto-version: ">=1.2.0"
5+
contributes:
6+
project:
7+
project:
8+
type: website
9+
pre-render:
10+
- refresh.ts
11+
- create-imports.lua
12+
- compile-imports.ts
13+
format: sverto-html
14+
formats:
15+
html:
16+
filters:
17+
- cleanup-transform.lua
18+
revealjs:
19+
filters:
20+
- cleanup-transform.lua
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- replaces the doc body with just its first block (assumed to be the
2+
-- version of the doc with transformed .svelte -> .js refs)
3+
Pandoc = function(doc)
4+
doc.blocks = doc.blocks[1].content
5+
return doc
6+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check if _extensions/svero exists or _extensions/360-info/sverto
2+
3+
import * as path from "https://deno.land/std/path/mod.ts";
4+
5+
const thisScript = path.fromFileUrl(import.meta.url);
6+
const rollupConfig = path.join(path.dirname(thisScript), "rollup.config.js");
7+
8+
// call rollup with the config file
9+
const cmd = ["npm", "run", "build", rollupConfig];
10+
const compileStep = Deno.run({ cmd });
11+
await compileStep.status();
12+
13+
// console.log("Svelte compilation + bundling done!");

0 commit comments

Comments
 (0)