Website bugfixes (#171)

This commit is contained in:
Tiffany Bennett 2024-05-04 15:23:30 -07:00 committed by GitHub
parent 2bb9122767
commit 07dc170897
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 11 deletions

View file

@ -95,6 +95,11 @@ function build_description(markdown_text)
j = j + 1 j = j + 1
end end
local first_p = HTML.select_one(body, "p")
if first_p then
HTML.add_class(first_p, "p-summary")
end
return body return body
end end

View file

@ -18,10 +18,13 @@
-- og:site_name field. -- og:site_name field.
site_title = soupault_config["custom_options"]["site_title"] site_title = soupault_config["custom_options"]["site_title"]
site_url = soupault_config["custom_options"]["site_url"]
-- Creates a `<meta>` tag and puts it into `<head>`. -- Creates a `<meta>` tag and puts it into `<head>`.
function add_meta(property, content) function add_meta(property, content)
if not content then return end if not content then
return
end
content = String.trim(content) content = String.trim(content)
content = Regex.replace_all(content, "\\s+", " ") content = Regex.replace_all(content, "\\s+", " ")
@ -31,12 +34,31 @@ function add_meta(property, content)
Log.error("No <head> element found") Log.error("No <head> element found")
end end
local existing =
HTML.select_one(head, 'meta[property="' .. property .. '"]')
if existing then
return
end
local meta = HTML.create_element("meta") local meta = HTML.create_element("meta")
HTML.set_attribute(meta, "content", content) HTML.set_attribute(meta, "content", content)
HTML.set_attribute(meta, "property", property) HTML.set_attribute(meta, "property", property)
HTML.append_child(head, meta) HTML.append_child(head, meta)
end end
if site_url then
-- not opengraph, but makes sense to put here.
-- this will probably not do the right thing if you have clean_urls off.
local canon = HTML.create_element("link")
HTML.set_attribute(canon, "rel", "canonical")
HTML.set_attribute(canon, "href", site_url .. page_url)
local head = HTML.select_one(page, "head")
if not head then
Log.error("No <head> element found")
end
HTML.append_child(head, canon)
end
-- required metadata: -- required metadata:
local type = "website" local type = "website"
if Sys.strip_extensions(Sys.basename(page_file)) ~= "index" then if Sys.strip_extensions(Sys.basename(page_file)) ~= "index" then
@ -50,7 +72,9 @@ add_meta("og:title", title)
local image_elt = HTML.select_one(page, ".e-content img") local image_elt = HTML.select_one(page, ".e-content img")
local image = image_elt and HTML.get_attribute(image_elt, "src") local image = image_elt and HTML.get_attribute(image_elt, "src")
local image_alt = image_elt and HTML.get_attribute(image_elt, "alt")
add_meta("og:image", image) add_meta("og:image", image)
add_meta("og:image:alt", image_alt)
local uid_elt = HTML.select_one(page, "span.u-uid") local uid_elt = HTML.select_one(page, "span.u-uid")
local uid = uid_elt and HTML.inner_text(uid_elt) local uid = uid_elt and HTML.inner_text(uid_elt)
@ -66,16 +90,19 @@ add_meta("og:site_name", site_title)
-- article metadata: -- article metadata:
if type == "article" then if type == "article" then
local published_elt = HTML.select_one(page, "time.dt-published") local published_elt = HTML.select_one(page, "time.dt-published")
local published = published_elt and HTML.get_attribute(published_elt, "datetime") local published = published_elt
published = published and Date.reformat(published, {"%Y-%m-%d"}, "%Y-%m-%dT%H:%M:%SZ") and HTML.get_attribute(published_elt, "datetime")
published = published
and Date.reformat(published, { "%Y-%m-%d" }, "%Y-%m-%dT%H:%M:%SZ")
add_meta("article:published_time", published) add_meta("article:published_time", published)
local updated_elt = HTML.select_one(page, "time.dt-updated") local updated_elt = HTML.select_one(page, "time.dt-updated")
local updated = updated_elt and HTML.get_attribute(updated_elt, "datetime") local updated = updated_elt and HTML.get_attribute(updated_elt, "datetime")
updated = updated and Date.reformat(updated, {"%Y-%m-%d"}, "%Y-%m-%dT%H:%M:%SZ") updated = updated
and Date.reformat(updated, { "%Y-%m-%d" }, "%Y-%m-%dT%H:%M:%SZ")
add_meta("article:modified_time", updated) add_meta("article:modified_time", updated)
local author_elt = HTML.select_one(page, ".h-card span.p-name") local author_elt = HTML.select_one(page, ".h-card .p-name")
local author = author_elt and HTML.inner_text(author_elt) local author = author_elt and HTML.inner_text(author_elt)
add_meta("article:author", author) add_meta("article:author", author)

View file

@ -51,7 +51,7 @@ main {
font-size: 80%; font-size: 80%;
} }
aside#toc ol { aside#toc>ol {
position: sticky; position: sticky;
top: 1em; top: 1em;
} }
@ -65,16 +65,23 @@ main {
padding-right: 0.75em; padding-right: 0.75em;
} }
nav > a {
padding: 0.3em;
}
nav > .nav-spacer { nav > .nav-spacer {
display: unset; display: unset;
flex-grow: 1; flex-grow: 1;
} }
} }
@media screen and (max-width: 384px) {
nav {
font-size: 14px;
}
nav svg {
width: 20px;
height: 20px;
}
}
main > article { main > article {
padding: 0.5em; padding: 0.5em;
padding-top: 0; padding-top: 0;
@ -91,6 +98,7 @@ nav {
border-bottom-color: var(--border); border-bottom-color: var(--border);
gap: 0.5em; gap: 0.5em;
margin-top: 0.25em; margin-top: 0.25em;
overflow-x: scroll;
} }
.nav-spacer { .nav-spacer {
@ -99,7 +107,7 @@ nav {
nav > a { nav > a {
text-decoration: none; text-decoration: none;
padding: 0.5em; padding: 0.3em;
border-bottom: 2px solid transparent; border-bottom: 2px solid transparent;
color: var(--link-normal); color: var(--link-normal);

View file

@ -76,3 +76,4 @@ widget = "opengraph"
[custom_options] [custom_options]
site_title = "Rink" site_title = "Rink"
site_url = "https://rinkcalc.app"