Skip to content

Commit 7f6205d

Browse files
authored
feat: single page (#1035)
* feat: spec state badges (#1036) * chore: update deps * fix: remove link shortcode * fix: remove old shortcodes * chore: rationalise js init- ensure all the js that is needed is bundled and initalised in an orderly manner. previously, shortcodes would include script elements to a remote cdn which can lead to many copies of the same lib being requested in single page mode. * fix: numbering per heading element. css counters are scoped to the element that first declares them. This change declares the counters at the content root, so that heading elements share them regardless of nesting. * fix: host katex locally * fix: dashboard links for single page. re-use the portable link template :woo hoo: * fix: multiple layout improvements * feat: bring back old ToC behaviour - This is a loving homage to the original ToC. It brings back all the old behaviours and great perf. TocBot perf is terrible on a large doc, so it is removed, in favour of the old ways. Fixes up resource loading, notably defering katex till well after the page is loaded, to speed up ToC build and reduce the time to get to a useable document. * chore: bring back appendix. fix glossary headings * remove header element that wraps headings to avoid issue with org-mode docs not getting headers re-written * fix missing section headers in content that ment the listings and appendix were missing * fix nesting of glossary headings * chore: fix header on small screens * match the old spec for generating heading ids and linking to them * fix issues with old content missing h1 elements. * document what is going on in render-heading and render-link so others may suffer less. License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>
1 parent 37e290d commit 7f6205d

File tree

121 files changed

+776
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+776
-324
lines changed

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ Random plain text context ...
175175
```
176176

177177

178-
## References
179-
### Markdown links **(Recommended)**
178+
## References - Markdown links
180179
These links use "portable links" just like `relref` so you can just give it the name of the file and it will fetch the correct relative link and title for the `<a href="/relative/path" title="page title">` automatically.
181180
You can override the `<a>` title by passing a second `string` in the link definition.
182181

@@ -193,19 +192,6 @@ You can override the `<a>` title by passing a second `string` in the link defini
193192

194193
```
195194

196-
### Hugo Cross Refs
197-
Check Hugo's documentation [here](https://gohugo.io/content-management/shortcodes/#ref-and-relref)
198-
```md
199-
[Random]({{<relref "randomness">}})
200-
[Pledge Collateral]({{<relref "storage_power_actor#pledge-collateral">}})
201-
```
202-
### Link shortcode
203-
Theres also `link` shortcode which will fetch the title of the page automatically and use it for the `<a>` text and title, but **DOES NOT** work with anchors (`#anchor-id`)
204-
```md
205-
{{<link storage_power_consensus>}}
206-
# <a href="/systems/filecoin_blockchain/storage_power_consensus" title="Storage Power Consensus">Storage Power Consensus</a>
207-
```
208-
209195
## Math mode
210196
For short snippets of math text you can just use the `{{<katex>}}` shortcode, but if you need to write lots of math in a page you can just use `math-mode` and avoid writting the katex shortcode everywhere.
211197

assets/_custom.scss

Lines changed: 121 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22

33
// Addons
44

5-
// @import "plugins/numbered";
5+
@import "plugins/numbered";
66
@import "plugins/scrollbars";
77
@import "plugins/toggles";
88
@import "table-sort";
99
@import "colors";
1010
@import "dashboard";
11+
@import "plugins/toc";
12+
@import "katex";
13+
14+
.markdown {
15+
overflow-x: hidden;
16+
h1, h2, h3, h4, h5, h6 {
17+
padding-top: 1.5rem;
18+
margin-bottom: 1rem;
19+
a {
20+
color: inherit;
21+
text-decoration: none;
22+
&:visited {
23+
color:inherit;
24+
}
25+
&:hover {
26+
text-decoration: none;
27+
&::after {
28+
font-size: 70%;
29+
padding-left:0.3em;
30+
color: $color-link;
31+
content: " #"
32+
}
33+
}
34+
}
35+
}
36+
}
37+
.section-badges {
38+
float: right;
39+
margin-top:-2.5rem;
40+
}
1141

1242
// SVG Diagrams
1343
.diagrams-container {
@@ -98,12 +128,43 @@
98128
}
99129

100130
// Tweaks
131+
html {
132+
scroll-behavior: auto;
133+
touch-action: auto;
134+
}
135+
.container {
136+
max-width: 89rem;
137+
}
138+
.book-menu {
139+
flex: 0 0 20rem;
140+
}
141+
.book-page {
142+
padding-top: 0rem;
143+
padding-left: 2rem;
144+
max-width: 52rem;
145+
}
146+
101147
summary {
102148
outline: none;
103149
}
104150
blockquote {
105151
overflow: auto;
106152
}
153+
.book-menu nav {
154+
width: 20rem;
155+
padding: 1rem 0.2rem 4rem 1rem;
156+
position: fixed;
157+
top: 0;
158+
bottom: 0;
159+
overflow-x: initial;
160+
overflow-y: hidden;
161+
}
162+
163+
.book-menu nav .toc {
164+
overflow-x: hidden;
165+
overflow-y: auto;
166+
height: 100%;
167+
}
107168

108169
.markdown>h1:first-of-type {
109170
margin-top: 0;
@@ -138,27 +199,33 @@ blockquote {
138199
padding: 0;
139200
height: 90vh;
140201
}
141-
.book-menu > nav::-webkit-scrollbar,
202+
.book-menu > nav .toc::-webkit-scrollbar,
142203
.book-toc > div nav::-webkit-scrollbar{
143204
width: 8px;
144205
}
145206

146-
.book-menu > nav::-webkit-scrollbar-thumb,
207+
.book-menu > nav .toc::-webkit-scrollbar-thumb,
147208
.book-toc > div nav::-webkit-scrollbar-thumb{
148209
background: transparent;
149210
}
150211

151-
.book-menu > nav:hover::-webkit-scrollbar-thumb,
152-
.book-toc > div nav:hover::-webkit-scrollbar-thumb{
212+
.book-menu > nav:hover .toc::-webkit-scrollbar-thumb,
213+
.book-toc > div nav:hover .toc::-webkit-scrollbar-thumb{
153214
background: rgba(255,255,255,.1);
154215
}
155216

156217
@media screen and (max-width: 56rem) {
157-
.toc {
158-
text-align: right;
218+
.book-page {
219+
padding-left:1rem;
220+
}
221+
.book-menu {
222+
visibility: hidden;
223+
margin-inline-start: -20rem;
224+
}
225+
#menu-control:checked~main .book-menu nav {
226+
transform: translateX(20rem);
159227
}
160228
.toc-label {
161-
margin: 0 0 2rem;
162229
font-weight:700;
163230
font-size:10px;
164231
.gg-menu-motion {
@@ -167,6 +234,15 @@ blockquote {
167234
}
168235
.book-header {
169236
margin-bottom: 2rem;
237+
position: fixed;
238+
width: 100%;
239+
background: white;
240+
z-index: 1;
241+
padding: 5px 0.6rem;
242+
box-shadow: 1px 0 2px 0px rgba(0,0,0,0.2);
243+
}
244+
#toc-depth-slider {
245+
display:none;
170246
}
171247
}
172248

@@ -182,19 +258,21 @@ blockquote {
182258
.toc {
183259
top:78px;
184260
}
185-
.toc-label, .dark-mode-toggle-label {
186-
font-size: 10px;
187-
font-weight: 700;
188-
display: block;
189-
}
190-
.gg-menu-motion, .gg-dark-mode {
191-
display: inline-block;
192-
margin-left: 0;
193-
margin-right: 0;
194-
vertical-align: middle;
195-
font-size: 10px;
196-
transform: scale(0.7);
197-
}
261+
}
262+
263+
.toc-label, .dark-mode-toggle-label {
264+
font-size: 10px;
265+
font-weight: 700;
266+
display: block;
267+
color:$gray-600;
268+
}
269+
.gg-menu-motion, .gg-dark-mode {
270+
display: inline-block;
271+
margin-left: 0;
272+
margin-right: 0;
273+
vertical-align: middle;
274+
font-size: 10px;
275+
transform: scale(0.7);
198276
}
199277

200278
// Colors
@@ -411,7 +489,7 @@ i[class^="gg-"] {
411489
box-shadow: 4px -6px 0,8px -12px 0;
412490
border-radius: 4px;
413491
background: currentColor
414-
}
492+
}
415493

416494
.gg-dark-mode {
417495
box-sizing: border-box;
@@ -453,3 +531,24 @@ i[class^="gg-"] {
453531
right:4px;
454532
top:4px
455533
}
534+
535+
.state-badge {
536+
font-size: 10px;
537+
font-weight: 500;
538+
}
539+
.state-badge-link {
540+
text-decoration: none !important;
541+
color: white !important;
542+
&:hover {
543+
text-decoration: none;
544+
}
545+
}
546+
.state-badge-key, .state-badge-value {
547+
padding: 2px 5px;
548+
}
549+
.state-badge-key {
550+
background-color: #555;
551+
}
552+
.section-intro .state-badge {
553+
display: none;
554+
}

assets/_katex.scss

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

assets/_variables.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/* You can override SASS variables here. */
22

33
$book-search-results-bg: #f8f9fa !default;
4+
5+
$blue: rgb(14,120,254);
6+
$color-link: $blue;

assets/katex.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import renderMathInElement from 'katex/dist/contrib/auto-render.mjs'
2+
3+
function initKatex () {
4+
console.log('init katex')
5+
document.querySelectorAll('.math-mode').forEach(function (el) {
6+
renderMathInElement(el, {
7+
ignoredTags: ["script", "noscript", "style", "textarea"],
8+
throwOnError: false,
9+
delimiters: [
10+
{left: "$$", right: "$$", display: true},
11+
{left: "$", right: "$", display: false},
12+
{left: "\\(", right: "\\)", display: false},
13+
{left: "\\[", right: "\\]", display: true}
14+
]
15+
})
16+
})
17+
}
18+
19+
window.addEventListener('load', () => {
20+
setTimeout(initKatex, 2000)
21+
});

assets/main.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import '@pwabuilder/pwaupdate'
2+
import { initToc } from './toc.js'
3+
import panzoom from 'panzoom'
4+
import tablesort from 'tablesort'
5+
import Gumshoe from 'gumshoejs'
6+
7+
// Note: the tablesort lib is not ESM friendly, and the sorts expect `Tablesort` to be available on the global
8+
window.Tablesort = tablesort
9+
require('tablesort/dist/sorts/tablesort.number.min.js')
10+
11+
function initPanZoom () {
12+
console.log('init panzoom')
13+
var elements = document.querySelectorAll(".zoomable")
14+
elements.forEach(function (el) {
15+
panzoom(el.querySelector('*:first-child'), {
16+
maxZoom: 10,
17+
minZoom: 0.5
18+
})
19+
})
20+
}
21+
22+
function initTableSort () {
23+
console.log('init tablesort')
24+
var elements = document.querySelectorAll(".tablesort")
25+
elements.forEach(function (el) {
26+
tablesort(el);
27+
})
28+
}
29+
30+
function initTocDepthSlider () {
31+
var slider = document.getElementById('toc-depth-slider')
32+
var toc = document.querySelector('.toc')
33+
34+
slider.addEventListener('change', (event) => {
35+
handleSliderChange(Number(event.target.value))
36+
})
37+
38+
function handleSliderChange (depth) {
39+
console.log('handleSliderChange', depth)
40+
for (let i = 0; i < 6; i++) {
41+
toc.querySelectorAll(`.depth-${i}`).forEach(el => {
42+
if (i < depth) {
43+
el.classList.remove('maybe-hide')
44+
} else {
45+
el.classList.add('maybe-hide')
46+
}
47+
})
48+
}
49+
}
50+
// init to the current value
51+
handleSliderChange(slider.value)
52+
}
53+
54+
function initTocScrollSpy () {
55+
console.log('initTocScrollSpy')
56+
var spy = new Gumshoe('.toc a', {
57+
nested: true,
58+
nestedClass: 'active-parent'
59+
})
60+
}
61+
62+
window.addEventListener('DOMContentLoaded', () => {
63+
initToc({tocSelector:'.toc', contentSelector: '.markdown'})
64+
initTocDepthSlider()
65+
initTocScrollSpy()
66+
initPanZoom()
67+
initTableSort()
68+
});

0 commit comments

Comments
 (0)