Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f58c860

Browse files
committed
Push to GitHub pages with actions
1 parent cf055df commit f58c860

File tree

5 files changed

+65
-36
lines changed

5 files changed

+65
-36
lines changed

.github/workflows/main.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
name: Github Pages
2-
on: [push]
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["main"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow one concurrent deployment
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: true
22+
323
jobs:
4-
build-and-deploy:
24+
# Single deploy job since we're just deploying
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
529
runs-on: ubuntu-latest
630
steps:
731
- name: Checkout
8-
uses: actions/checkout@master
32+
uses: actions/checkout@v3
933

1034
- name: Setup Ruby
1135
uses: ruby/setup-ruby@v1
@@ -16,17 +40,23 @@ jobs:
1640
- name: Setup node
1741
uses: actions/setup-node@v2
1842
with:
19-
node-version: 14.x
43+
node-version: 18.x
2044
cache: yarn
2145

46+
- name: Setup Pages
47+
uses: actions/configure-pages@v3
48+
2249
- name: Package application
2350
run: |
2451
bundle exec rake
2552
yarn install --frozen-lockfile
2653
yarn build
2754
28-
- name: Deploy
29-
uses: peaceiris/actions-gh-pages@v3
55+
- name: Upload artifact
56+
uses: actions/upload-pages-artifact@v1
3057
with:
31-
github_token: ${{ secrets.GITHUB_TOKEN }}
32-
publish_dir: ./docs
58+
path: './docs'
59+
60+
- name: Deploy to GitHub Pages
61+
id: deployment
62+
uses: actions/deploy-pages@v1

docs/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ <h1>Syntax Tree</h1>
2323
</select>
2424
</div>
2525
</nav>
26-
<textarea id="editor">1 + 2 * 3</textarea>
26+
<textarea id="editor">def fibonacci(n)
27+
(n == 0 || n == 1) ? n : fibonacci(n - 1) + fibonacci(n - 2)
28+
end
29+
</textarea>
2730
<textarea id="output" disabled readonly>Loading...</textarea>
28-
<div id="graph-container" class="graph-container"></div>
31+
<div id="graph" class="graph">Loading...</div>
2932
</main>
3033
<script type="module" src="index.js"></script>
3134
</body>

src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ select {
5353
min-width: 15em;
5454
}
5555

56-
.graph-container {
56+
.graph {
5757
text-align: center;
5858
overflow-y: scroll;
5959
overflow-x: scroll;

src/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ await Promise.all([
1818
}
1919
});
2020
}),
21-
import("./mermaid"),
21+
// We're going to load mermaid asynchronously because it is a large module.
22+
// When it gets loaded we'll tell it not to run on load and then we'll use it
23+
// when the user selects the graph.
24+
import("./mermaid").then(({ default: mermaid }) => {
25+
mermaid.initialize({ startOnLoad: false });
26+
return mermaid;
27+
}),
2228
// We're going to load the Ruby VM chunk asynchronously because it is pretty
2329
// dang huge (> 40Mb). In the meantime the textarea that is holding the place
2430
// of the actual functional one is just going to display "Loading...".
@@ -30,6 +36,9 @@ await Promise.all([
3036
output.value = ruby.prettyPrint(editor.getValue());
3137
output.disabled = false;
3238

39+
// Next, grab a reference to the graph container element.
40+
const graph = document.getElementById("graph");
41+
3342
// This is the function that will be used to display the output from the
3443
// source.
3544
let displayFunction = ruby.prettyPrint;
@@ -43,12 +52,17 @@ await Promise.all([
4352

4453
if (event.detail.kind === "mermaid") {
4554
output.setAttribute("style", "display: none;");
46-
mermaid.render(source);
55+
graph.setAttribute("style", "text-align: left;")
56+
graph.innerHTML = "Loading..."
57+
58+
mermaid.render("preparedScheme", source).then(({ svg }) => {
59+
graph.innerHTML = svg;
60+
graph.setAttribute("style", "display: block; text-align: center;");
61+
});
4762
} else {
4863
output.value = source;
4964
output.setAttribute("style", "");
50-
51-
mermaid.reset();
65+
graph.setAttribute("style", "display: none;");
5266
}
5367
} catch (error) {
5468
// For now, just ignoring the error. Eventually I'd like to make this mark

src/mermaid.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
import mermaidjs from "mermaid";
1+
import mermaid from "mermaid";
22

3-
const getCleanContainer = () => {
4-
const div = document.querySelector("#graph-container");
5-
div.innerHTML = "";
6-
return div;
7-
}
8-
9-
const render = async (source) => {
10-
let container = getCleanContainer();
11-
12-
container.setAttribute("style", "display: block;");
13-
14-
mermaidjs.initialize({ startOnLoad: false });
15-
const { svg } = await mermaidjs.render('preparedScheme', source);
16-
container.innerHTML = svg;
17-
}
18-
19-
const reset = () => getCleanContainer().setAttribute("style", "display: none;");
20-
21-
export { render, reset };
3+
export default mermaid;

0 commit comments

Comments
 (0)