Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website bugfixes #171

Merged
merged 5 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions web/plugins/fetch-releases.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ function build_description(markdown_text)
j = j + 1
end

local first_p = HTML.select_one(body, "p")
if first_p then
HTML.add_class(first_p, "p-summary")
end

return body
end

Expand Down
37 changes: 32 additions & 5 deletions web/plugins/opengraph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
-- og:site_name field.

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>`.
function add_meta(property, content)
if not content then return end
if not content then
return
end

content = String.trim(content)
content = Regex.replace_all(content, "\\s+", " ")
Expand All @@ -31,12 +34,31 @@ function add_meta(property, content)
Log.error("No <head> element found")
end

local existing =
HTML.select_one(head, 'meta[property="' .. property .. '"]')
if existing then
return
end

local meta = HTML.create_element("meta")
HTML.set_attribute(meta, "content", content)
HTML.set_attribute(meta, "property", property)
HTML.append_child(head, meta)
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:
local type = "website"
if Sys.strip_extensions(Sys.basename(page_file)) ~= "index" then
Expand All @@ -50,7 +72,9 @@ add_meta("og:title", title)

local image_elt = HTML.select_one(page, ".e-content img")
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:alt", image_alt)

local uid_elt = HTML.select_one(page, "span.u-uid")
local uid = uid_elt and HTML.inner_text(uid_elt)
Expand All @@ -66,16 +90,19 @@ add_meta("og:site_name", site_title)
-- article metadata:
if type == "article" then
local published_elt = HTML.select_one(page, "time.dt-published")
local published = published_elt and HTML.get_attribute(published_elt, "datetime")
published = published and Date.reformat(published, {"%Y-%m-%d"}, "%Y-%m-%dT%H:%M:%SZ")
local published = published_elt
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)

local updated_elt = HTML.select_one(page, "time.dt-updated")
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)

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)
add_meta("article:author", author)

Expand Down
20 changes: 14 additions & 6 deletions web/site/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ main {
font-size: 80%;
}

aside#toc ol {
aside#toc>ol {
position: sticky;
top: 1em;
}
Expand All @@ -65,16 +65,23 @@ main {
padding-right: 0.75em;
}

nav > a {
padding: 0.3em;
}

nav > .nav-spacer {
display: unset;
flex-grow: 1;
}
}

@media screen and (max-width: 384px) {
nav {
font-size: 14px;
}

nav svg {
width: 20px;
height: 20px;
}
}

main > article {
padding: 0.5em;
padding-top: 0;
Expand All @@ -91,6 +98,7 @@ nav {
border-bottom-color: var(--border);
gap: 0.5em;
margin-top: 0.25em;
overflow-x: scroll;
}

.nav-spacer {
Expand All @@ -99,7 +107,7 @@ nav {

nav > a {
text-decoration: none;
padding: 0.5em;
padding: 0.3em;
border-bottom: 2px solid transparent;

color: var(--link-normal);
Expand Down
1 change: 1 addition & 0 deletions web/soupault.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ widget = "opengraph"

[custom_options]
site_title = "Rink"
site_url = "https://rinkcalc.app"
Loading