Skip to content

Commit

Permalink
Update manual generator for 0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Jun 29, 2024
1 parent 526eb95 commit 1161609
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 154 deletions.
6 changes: 3 additions & 3 deletions docs/inko.pkg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require https://github.com/yorickpeterse/inko-wobsite 0.13.0 086ccf8634e494f18fed2c72329567a39c726012
require https://github.com/yorickpeterse/inko-builder 0.11.0 ae7b8cf3476dfc401408c493bd6d795bd0ac3ab2
require https://github.com/yorickpeterse/inko-markdown 0.15.0 48cf0e8276522870a601f857f672c5a11c5eda37
require https://github.com/yorickpeterse/inko-wobsite 0.17.0 1078263e2219842fcfeed309ef57acd803f0501a
require https://github.com/yorickpeterse/inko-builder 0.12.0 dfb7877ca9dec2109b0fa940190c210dd3fe4059
require https://github.com/yorickpeterse/inko-markdown 0.20.0 f3e1021ac8eb00ddca6490d26c49b4c82524d23c
30 changes: 15 additions & 15 deletions docs/src/docs/config.inko
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import docs.menu.Menu
import std.clone.Clone
import std.fs.path.Path
import wobsite.Page
import docs.menu (Menu)
import std.clone (Clone)
import std.fs.path (Path)
import wobsite (Page)

let MENU_FILE = 'menu.json'

Expand All @@ -18,24 +18,24 @@ class pub Config {
fn pub static new(source: ref Path) -> Result[Config, String] {
let menu = try Menu.parse(source, Path.new(MENU_FILE))

Result.Ok({Config {
@title = 'The Inko manual',
@base_url = 'https://docs.inko-lang.org/manual',
@menu = menu,
}})
Result.Ok(
{
Config(
title: 'The Inko manual',
base_url: 'https://docs.inko-lang.org/manual',
menu: menu,
)
},
)
}

fn canonical_url(page: ref Page) -> String {
"{@base_url}/latest{page.url}"
'${@base_url}/latest${page.url}'
}
}

impl Clone[Config] for Config {
fn pub clone -> Config {
Config {
@title = @title,
@base_url = @base_url,
@menu = @menu.clone,
}
Config(title: @title, base_url: @base_url, menu: @menu.clone)
}
}
15 changes: 8 additions & 7 deletions docs/src/docs/filters.inko
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import builder.html.(Document, Element)
import docs.menu.Menu
import docs.url.(link_from, relative?)
import markdown.html.(Filter, TableOfContents)
import wobsite.Page
import wobsite.url.(relative_to_absolute)
import builder.html (Document, Element)
import docs.menu (Menu)
import docs.url (link_from, relative?)
import markdown.html (Filter, TableOfContents)
import wobsite (Page)
import wobsite.url (relative_to_absolute)

# A filter that automatically inserts a table of contents.
class AutoTableOfContents {
fn static new -> AutoTableOfContents {
AutoTableOfContents {}
AutoTableOfContents()
}

fn add_marker(document: mut Document) {
Expand Down Expand Up @@ -56,6 +56,7 @@ class RelativeLinks {
let mut abs = relative_to_absolute(@page.url, relative, as_file: false)

if abs.ends_with?('/').false? { abs = abs + '/' }

@menu.titles.opt(abs)
}
}
Expand Down
154 changes: 75 additions & 79 deletions docs/src/docs/layouts.inko
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import builder.html
import builder.xml
import docs.config.Config
import docs.filters.(AutoTableOfContents, RelativeLinks)
import docs.menu.(Item, Menu)
import docs.url.(link_from)
import markdown.html.(Filter, TableOfContents)
import std.string.StringBuffer
import wobsite.(Files, Page)
import wobsite.markdown.(Admonitions, SyntaxHighlight)
import wobsite.time.(human_readable_date, iso_date)
import docs.config (Config)
import docs.filters (AutoTableOfContents, RelativeLinks)
import docs.menu (Item, Menu)
import docs.url (link_from)
import markdown.html (Filter, TableOfContents)
import std.string (StringBuffer)
import wobsite (Files, Page)
import wobsite.markdown (Admonitions, SyntaxHighlight)
import wobsite.time (human_readable_date, iso_date)

fn filters(menu: ref Menu, page: ref Page) -> Array[Filter] {
[
SyntaxHighlight.new as Filter,
Admonitions.new as Filter,
RelativeLinks { @menu = menu, @page = page } as Filter,
AutoTableOfContents {} as Filter, # This filter must come last
RelativeLinks(menu: menu, page: page) as Filter,
AutoTableOfContents() as Filter, # This filter must come last
]
}

Expand Down Expand Up @@ -57,22 +57,26 @@ fn sidebar_list(
page: ref Page,
) {
root.header.h1.text(title)
root.ul.with fn (ul) {
items.iter.each fn (item) {
root.ul.with(fn (ul) {
items.iter.each(fn (item) {
let a = ul.li.a

if item.url == page.url { a.attr('class', 'current') }

a.attr('href', link_from(page, item.url)).text(item.title)
}
}
})
})
}

fn sidebar(config: ref Config, root: mut html.Element, page: ref Page) {
let section = config.menu.items.iter.find fn (pair) {
pair.value.iter.any? fn (item) { item.url == page.url }
}
let section = config.menu.items.iter.find(fn (pair) {
pair.value.iter.any?(fn (item) { item.url == page.url })
})

let pair = match section { case Some(v) -> v, case _ -> return }
let pair = match section {
case Some(v) -> v
case _ -> return
}
let left = root.aside.attr('class', 'left')

sidebar_list(left, pair.key, pair.value, page)
Expand All @@ -81,9 +85,9 @@ fn sidebar(config: ref Config, root: mut html.Element, page: ref Page) {
fn home_sidebar(config: ref Config, root: mut html.Element, page: ref Page) {
let left = root.aside.attr('class', 'left')

config.menu.items.iter.each fn (pair) {
config.menu.items.iter.each(fn (pair) {
sidebar_list(left, pair.key, pair.value, page)
}
})
}

fn toggle_menu(query: String, open: String, close: String) -> html.Element {
Expand All @@ -107,38 +111,27 @@ fn head(config: ref Config, page: ref Page) -> html.Element {
.meta
.attr(
'content',
"\
default-src 'self'; \
script-src 'self'; \
object-src 'none'; \
style-src 'self'; \
font-src 'self' data:; \
base-uri 'none'; \
form-action 'none'; \
"
"default-src 'self'; script-src 'self'; object-src 'none'; style-src 'self'; font-src 'self' data:; base-uri 'none'; form-action 'none';",
)
.attr('http-equiv', 'Content-Security-Policy')

head.meta.attr('charset', 'utf-8')

head
.meta
.attr('name', 'viewport')
.attr('content', 'width=device-width, initial-scale=1.0')
head.meta.attr('name', 'viewport').attr(
'content',
'width=device-width, initial-scale=1.0',
)

head
.link
.attr('rel', 'icon')
.attr('href', link_from(page, '/favicon.ico'))
.attr('type', 'image/x-icon')

head
.script
.attr('src', link_from(page, '/js/main.js'))
.attr('defer', 'defer')
head.script.attr('src', link_from(page, '/js/main.js')).attr('defer', 'defer')

head.add(link(link_from(page, '/css/reset.css'), rel: 'stylesheet'))
head.add(link(link_from(page, '/css/icons.css'), rel: 'stylesheet'))
head.add(link(link_from(page, '/css/icons.css'), rel: 'stylesheet'))
head.add(link(link_from(page, '/css/main.css'), rel: 'stylesheet'))
head.add(link(config.canonical_url(page), rel: 'canonical'))
head.title.text(page.title)
Expand All @@ -148,36 +141,39 @@ fn head(config: ref Config, page: ref Page) -> html.Element {
fn header(config: ref Config, page: ref Page) -> html.Element {
let root = html.Element.new('div')

root.attr('class', 'top-bar').header.attr('class', 'grid').with fn (h) {
h.div.attr('class', 'logo').with fn (logo) {
root.attr('class', 'top-bar').header.attr('class', 'grid').with(fn (h) {
h.div.attr('class', 'logo').with(fn (logo) {
logo
.img
.attr('src', link_from(page, '/images/logo.png'))
.attr('height', '24')
.attr('width', '24')

logo.span.text(config.title)
}
})

h.div.attr('class', 'expand-menus').with fn (div) {
h.div.attr('class', 'expand-menus').with(fn (div) {
div.add(toggle_menu('.top-bar nav', 'Show menu', 'Hide menu'))
div.add(toggle_menu('.page aside.left', 'Show chapters', 'Hide chapters'))
}
})

h.nav.ul.with fn (ul) {
config.menu.items.iter.each fn (pair) {
let item =
match pair.value.opt(0) { case Some(v) -> v, case _ -> return }
h.nav.ul.with(fn (ul) {
config.menu.items.iter.each(fn (pair) {
let item = match pair.value.opt(0) {
case Some(v) -> v
case _ -> return
}

ul.li.a.attr('href', link_from(page, item.url)).with fn (a) {
ul.li.a.attr('href', link_from(page, item.url)).with(fn (a) {
a.text(pair.key)

if page.url.starts_with?(item.parent_url) or page.url == item.url {
a.attr('class', 'current')
}
}
}
}
}
})
})
})
})

root
}
Expand All @@ -191,54 +187,54 @@ fn container(
}

fn pub home(config: ref Config, page: Page) -> html.Document {
let doc = html.Document.html('en') fn (html) {
let doc = html.Document.html('en', fn (html) {
html.add(head(config, page))
html.body.with fn (body) {
html.body.with(fn (body) {
body.add(header(config, page))
container(body, 'page home') fn (div) {
container(body, 'page home', fn (div) {
home_sidebar(config, div, page)
content(config.menu, page, div)
}
}
}
})
})
})

doc
}

fn pub page(config: ref Config, page: Page) -> html.Document {
let doc = html.Document.html('en') fn (html) {
let doc = html.Document.html('en', fn (html) {
html.add(head(config, page))
html.body.with fn (body) {
html.body.with(fn (body) {
body.add(header(config, page))
container(body, 'page') fn (div) {
container(body, 'page', fn (div) {
sidebar(config, div, page)
content(config.menu, page, div)
}
}
}
})
})
})

doc
}

fn pub missing(config: ref Config, page: Page) -> html.Document {
html.Document.html('en') fn (html) {
html.Document.html('en', fn (html) {
html.add(head(config, page))
html.body.with fn (body) {
html.body.with(fn (body) {
body.add(header(config, page))
container(body, 'missing-page') fn (div) {
div.article.with fn (article) {
article.header.with fn (h) {
h
.img
.attr('src', link_from(page, '/images/404.gif'))
.attr('height', '255')
container(body, 'missing-page', fn (div) {
div.article.with(fn (article) {
article.header.with(fn (h) {
h.img.attr('src', link_from(page, '/images/404.gif')).attr(
'height',
'255',
)

h.h1.text(page.title)
}
})

article.append(page.to_html(filters(config.menu, page)))
}
}
}
}
})
})
})
})
}
Loading

0 comments on commit 1161609

Please sign in to comment.