start migration to bundle format
This commit is contained in:
parent
64e270a868
commit
7fe9b99535
13 changed files with 378 additions and 470 deletions
|
|
@ -4,10 +4,14 @@
|
|||
|
||||
/// Generate the html <head> element for the page.
|
||||
#let html-head(
|
||||
/// Page url,
|
||||
url,
|
||||
/// The base url of the site (eg: "http://test.example.com")
|
||||
base-url,
|
||||
/// The url path of the page (full url of the page is base-url + path), eg: "/index.html"
|
||||
path,
|
||||
/// Title of the page
|
||||
title,
|
||||
/// Label of the page
|
||||
page-label,
|
||||
/// Path to the icon (TODO: /!\ must be an url, typst image not yet supported)
|
||||
icon: none,
|
||||
/// Type of the page for open-graph data
|
||||
|
|
@ -25,6 +29,7 @@
|
|||
/// List of related sites for metadata
|
||||
me-links: (),
|
||||
) = {
|
||||
let url = base-url + path
|
||||
html.head({
|
||||
html.meta(charset: "utf-8")
|
||||
if title != none {
|
||||
|
|
@ -95,9 +100,9 @@
|
|||
}
|
||||
}}
|
||||
|
||||
get-css()
|
||||
get-js()
|
||||
context for tag in additionnal-head-tags.final() {
|
||||
get-css(page-label)
|
||||
get-js(page-label)
|
||||
context for tag in additionnal-head-tags.at(label(str(page-label) + "-end")) {
|
||||
tag
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,7 @@
|
|||
#import "./states.typ": *
|
||||
#import "./figures.typ": show-rule-figure
|
||||
#import "./code.typ": show-rule-code-block
|
||||
|
||||
#let css-list = state("css-list", ())
|
||||
#let js-list = state("js-list", ())
|
||||
#let additionnal-head-tags = state("additionnal-head-tags", ())
|
||||
|
||||
/// Add string `css` to `css-list` if not already present
|
||||
#let add-css(css) = context {
|
||||
css-list.update(x => if css in x { x } else { x + (css,) })
|
||||
}
|
||||
|
||||
/// Add string `js` to `js-list` if not already present
|
||||
#let add-js(js) = context {
|
||||
js-list.update(x => if js in x { x } else { x + (js,) })
|
||||
}
|
||||
|
||||
/// Add additionnal html tag to insert in <head>
|
||||
#let add-tag-in-head(tag) = context {
|
||||
additionnal-head-tags.update(x => if tag in x { x } else { x + (tag, ) })
|
||||
}
|
||||
|
||||
/// Concatenate all css found in css-list at the end of the document
|
||||
#let get-css() = context {
|
||||
html.style(css-list.final().join("\n\n"))
|
||||
}
|
||||
|
||||
/// Concatenate all js found in js-list at the end of the document
|
||||
#let get-js() = context {
|
||||
html.script(js-list.final().join("\n\n"))
|
||||
}
|
||||
|
||||
#let html-show(body) = {
|
||||
show raw: it => {
|
||||
|
|
|
|||
26
lib/main.typ
26
lib/main.typ
|
|
@ -1,7 +1,8 @@
|
|||
#import "./html_head.typ": html-head
|
||||
#import "./html_body.typ": html-body
|
||||
#import "./html_utils.typ": html-show
|
||||
#import "./html_utils.typ": html-show, reset-page-states
|
||||
#import "./summary.typ": summary, card-list
|
||||
#import "./states.typ": current-page-label
|
||||
#import "./pyscript.typ": state-use-pyscript, state-pyscript-data-list, state-pyscript-version, state-pyscript-interpreters, state-pyscript-default-interpreter, pyscript-show, pyscript-data
|
||||
#import "./rss.typ": rss
|
||||
#import "./icons.typ"
|
||||
|
|
@ -9,8 +10,10 @@
|
|||
|
||||
/// Mail template function
|
||||
#let webpage(
|
||||
/// Page url
|
||||
url: none,
|
||||
/// The base url of the site (eg: "http://test.example.com")
|
||||
base-url: none,
|
||||
/// The url path of the page (full url of the page is base-url + path), eg: "/index.html"
|
||||
path: none,
|
||||
/// Title of the page, default to document.title
|
||||
title: none,
|
||||
/// Use only for html 'lang' attribute.
|
||||
|
|
@ -32,6 +35,8 @@
|
|||
stylesheets: (),
|
||||
/// List of related sites for metadata
|
||||
me-links: (),
|
||||
/// Label of the page (for links)
|
||||
page-label: none,
|
||||
/// Dictionnary of available pyscript-data for each versions of pyscript
|
||||
/// expected in the form of ("<version>": pyscript-data-list("<url>", { html.link(...) }), ...)
|
||||
pyscript-data-list: (:),
|
||||
|
|
@ -56,7 +61,9 @@
|
|||
/// Body of the page
|
||||
body
|
||||
) = {
|
||||
assert(type(url) == str, message: "A page must have an url")
|
||||
assert(type(base-url) == str, message: "A page must have a base url")
|
||||
assert(type(path) == str, message: "A page must have a path")
|
||||
|
||||
context {
|
||||
state-pyscript-data-list.update(x => pyscript-data-list)
|
||||
state-pyscript-interpreters.update(x => pyscript-interpreters)
|
||||
|
|
@ -65,10 +72,13 @@
|
|||
}
|
||||
show: html-show
|
||||
show raw.where(block: true, lang: "python-run"): pyscript-show
|
||||
current-page-label.update(x => page-label)
|
||||
html.html(lang: lang, {
|
||||
html-head(
|
||||
url,
|
||||
base-url,
|
||||
path,
|
||||
title,
|
||||
page-label,
|
||||
icon: icon,
|
||||
og-type: og-type,
|
||||
site-name: site-name,
|
||||
|
|
@ -84,7 +94,11 @@
|
|||
footer: footer,
|
||||
nav-elements: nav-elements,
|
||||
menu: menu,
|
||||
body
|
||||
[
|
||||
#body
|
||||
#metadata("end of page " + str(page-label)) #label(str(page-label) + "-end")
|
||||
]
|
||||
)
|
||||
reset-page-states()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
#import "./html_utils.typ": add-tag-in-head
|
||||
|
||||
#let state-use-pyscript = state("state-use-pyscript", false)
|
||||
#let state-pyscript-version = state("state-pyscript-version", none)
|
||||
#let state-pyscript-data-list = state("state-pyscript-data-list", (:))
|
||||
#let state-pyscript-interpreters = state("state-pyscript-interpreters", (:))
|
||||
#let state-pyscript-default-interpreter = state("state-pyscript-default-interpreter", none)
|
||||
#let state-pyscript-canvas-ids = state("state-pyscript-canvas-ids", ())
|
||||
#import "./states.typ": (
|
||||
state-use-pyscript,
|
||||
state-pyscript-version,
|
||||
state-pyscript-data-list,
|
||||
state-pyscript-interpreters,
|
||||
state-pyscript-default-interpreter,
|
||||
state-pyscript-canvas-ids,
|
||||
current-page-label,
|
||||
)
|
||||
|
||||
/// Define data needed to load a version of pyscript
|
||||
#let pyscript-data(
|
||||
|
|
@ -139,7 +141,9 @@
|
|||
if canvas-attr != none {
|
||||
html.elem("canvas", attrs: ("id": canvas-attr))
|
||||
|
||||
let core-js-url = state-pyscript-data-list.final().at(state-pyscript-version.final()).core-js-url
|
||||
let page-label = current-page-label.at(here())
|
||||
let end-page-label = label(str(page-label) + "-end")
|
||||
let core-js-url = state-pyscript-data-list.at(end-page-label).at(state-pyscript-version.at(end-page-label)).core-js-url
|
||||
add-tag-in-head(
|
||||
html.script(
|
||||
type: "module",
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@
|
|||
"item",
|
||||
children: (
|
||||
xml-tag("title", body: it.document-args.title),
|
||||
xml-tag("link", body: it.template-args.url),
|
||||
xml-tag("guid", body: it.template-args.url),
|
||||
xml-tag("link", body: it.template-args.base-url + it.template-args.path),
|
||||
xml-tag("guid", body: it.template-args.base-url + it.template-args.path),
|
||||
xml-tag("description", body: it.document-args.description),
|
||||
xml-tag("pubDate", body: it.document-args.date.display(date-format-rfc822)),
|
||||
) + it.template-args.tags.map(tag => xml-tag("category", body: tag))
|
||||
|
|
|
|||
57
lib/states.typ
Normal file
57
lib/states.typ
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
// Pyscript
|
||||
#let state-use-pyscript = state("state-use-pyscript", false)
|
||||
#let state-pyscript-version = state("state-pyscript-version", none)
|
||||
#let state-pyscript-data-list = state("state-pyscript-data-list", (:))
|
||||
#let state-pyscript-interpreters = state("state-pyscript-interpreters", (:))
|
||||
#let state-pyscript-default-interpreter = state("state-pyscript-default-interpreter", none)
|
||||
#let state-pyscript-canvas-ids = state("state-pyscript-canvas-ids", ())
|
||||
|
||||
#let reset-pyscript-page-states() = {
|
||||
state-use-pyscript.update(x => false)
|
||||
state-pyscript-version.update(x => state-pyscript-version)
|
||||
state-pyscript-data-list.update(x => (:))
|
||||
state-pyscript-interpreters.update(x => (:))
|
||||
state-pyscript-default-interpreter.update(x => none)
|
||||
state-pyscript-canvas-ids.update(x => ())
|
||||
}
|
||||
|
||||
// CSS / JS / misc tags
|
||||
#let current-page-label = state("current-page-label", none)
|
||||
#let css-list = state("css-list", ())
|
||||
#let js-list = state("js-list", ())
|
||||
#let additionnal-head-tags = state("additionnal-head-tags", ())
|
||||
|
||||
/// Add string `css` to `css-list` if not already present
|
||||
#let add-css(css) = context {
|
||||
css-list.update(x => if css in x { x } else { x + (css,) })
|
||||
}
|
||||
|
||||
/// Add string `js` to `js-list` if not already present
|
||||
#let add-js(js) = context {
|
||||
js-list.update(x => if js in x { x } else { x + (js,) })
|
||||
}
|
||||
|
||||
/// Add additionnal html tag to insert in <head>
|
||||
#let add-tag-in-head(tag) = context {
|
||||
additionnal-head-tags.update(x => if tag in x { x } else { x + (tag, ) })
|
||||
}
|
||||
|
||||
/// Concatenate all css found in css-list at the end of the document
|
||||
#let get-css(page-label) = context {
|
||||
html.style(css-list.at(label(str(page-label) + "-end")).join("\n\n"))
|
||||
}
|
||||
|
||||
/// Concatenate all js found in js-list at the end of the document
|
||||
#let get-js(page-label) = context {
|
||||
html.script(js-list.at(label(str(page-label) + "-end")).join("\n\n"))
|
||||
}
|
||||
|
||||
#let reset-page-states() = {
|
||||
current-page-label.update(x => none)
|
||||
css-list.update(x => ())
|
||||
js-list.update(x => ())
|
||||
additionnal-head-tags.update(x => ())
|
||||
reset-pyscript-page-states()
|
||||
}
|
||||
|
||||
|
|
@ -81,15 +81,15 @@
|
|||
```
|
||||
chtml.summary-card({
|
||||
chtml.summary-card-preview({
|
||||
html.a(href: summ.template-args.url, summ.preview-image)
|
||||
link(summ.template-args.page-label, summ.preview-image)
|
||||
if summ.img-copyright != none {
|
||||
html.small[Image: #sym.copyright #summ.img-copyright]
|
||||
}
|
||||
})
|
||||
chtml.summary-card-description({
|
||||
heading(level: 2, html.a(href: summ.template-args.url, summ.document-args.title))
|
||||
heading(level: 2, link(summ.template-args.page-label, summ.document-args.title))
|
||||
|
||||
html.a(href: summ.template-args.url, summ.document-args.description)
|
||||
link(summ.template-args.page-label, summ.document-args.description)
|
||||
|
||||
chtml.summary-card-details(summ.document-args.date.display())
|
||||
chtml.tag-box(for tag in summ.template-args.tags { html.span(class: ("tag",), "#" + tag) })
|
||||
|
|
@ -101,8 +101,10 @@
|
|||
/// Store data form `set document(...)` and `show: webpage.with(...)` in `summ.document-args` and `summ.template-args`,
|
||||
/// and generate a summary card that can be used as a link for the page.
|
||||
#let summary(
|
||||
/// The url of the page
|
||||
url: none,
|
||||
/// The base url of the site (eg: "http://test.example.com")
|
||||
base-url: none,
|
||||
/// The url path of the page (full url of the page is base-url + path), eg: "/index.html"
|
||||
path: none,
|
||||
/// The title of the page
|
||||
title: none,
|
||||
/// The image preview of the page.
|
||||
|
|
@ -119,14 +121,21 @@
|
|||
date: none,
|
||||
/// Tags associated to the content of the page
|
||||
tags: (),
|
||||
/// Label of the page (for links)
|
||||
page-label: none,
|
||||
) = {
|
||||
assert(type(url) == str, message: "summary() must have an url")
|
||||
assert(type(base-url) == str, message: "summary() must have a base url")
|
||||
assert(type(path) == str, message: "summary() must have a path")
|
||||
assert(type(title) == str or type(title) == content, message: "summary() must have title")
|
||||
assert(type(preview-image) != none, message: "summary() must have a preview-image")
|
||||
assert(type(author) != none, message: "summary() must have at least one author")
|
||||
assert(type(description) != none, message: "summary() must have a description")
|
||||
assert(type(date) != none, message: "summary() must have a date")
|
||||
|
||||
if page-label == none {
|
||||
page-label = label(path)
|
||||
}
|
||||
|
||||
let summ = (
|
||||
document-args: (
|
||||
title: title,
|
||||
|
|
@ -135,9 +144,12 @@
|
|||
date: date,
|
||||
),
|
||||
template-args: (
|
||||
url: url,
|
||||
base-url: base-url,
|
||||
path: path,
|
||||
tags: tags,
|
||||
page-label: page-label,
|
||||
),
|
||||
path: path,
|
||||
preview-image: preview-image,
|
||||
img-copyright: img-copyright,
|
||||
card: []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue