1
Fork 0

change the way branch permalinks work

branch permalinks still use /b, but /b?abc now acts as a redirect rather than doing annoying JavaScript garbage
I changed the branch element ID format to accomodate this---now the IDs are of form `b-{id}` rather than `{tree_path}:{id}`.
the old way was stupid anyways.

I hope nothing breaks too majorly because of this.
This commit is contained in:
リキ萌 2025-01-11 00:15:29 +01:00
parent 70be482fb7
commit c537eb844f
8 changed files with 26 additions and 66 deletions
crates/treehouse/src
static
css/page
js
template/components

View file

@ -23,7 +23,7 @@ use tracing::{info, instrument};
use crate::dirs::Dirs; use crate::dirs::Dirs;
use crate::sources::Sources; use crate::sources::Sources;
use crate::vfs::asynch::AsyncDir; use crate::vfs::asynch::AsyncDir;
use crate::vfs::VPath; use crate::vfs::{self, VPath};
use crate::{html::EscapeHtml, state::Source}; use crate::{html::EscapeHtml, state::Source};
mod system { mod system {
@ -159,36 +159,12 @@ async fn branch(RawQuery(named_id): RawQuery, State(state): State<Arc<Server>>)
}); });
if let Some(branch_id) = branch_id { if let Some(branch_id) = branch_id {
let branch = state.sources.treehouse.tree.branch(branch_id); let branch = state.sources.treehouse.tree.branch(branch_id);
if let Source::Tree { input, tree_path } = if let Source::Tree { tree_path, .. } = state.sources.treehouse.source(branch.file_id) {
state.sources.treehouse.source(branch.file_id) if let Some(url) =
vfs::url(&state.sources.config.site, &state.target.sync(), tree_path)
{ {
if let Some(content) = state let url = format!("{url}#{}", branch.html_id);
.target return (StatusCode::FOUND, [(LOCATION, url)]).into_response();
.content(tree_path)
.await
.and_then(|c| c.string().ok())
{
let branch_markup = input[branch.content.clone()].trim();
let mut per_page_metadata =
String::from("<meta property=\"og:description\" content=\"");
write!(per_page_metadata, "{}", EscapeHtml(branch_markup)).unwrap();
per_page_metadata.push_str("\">");
per_page_metadata.push_str(r#"<meta name="robots" content="noindex">"#);
const PER_PAGE_METADATA_REPLACEMENT_STRING: &str = "<!-- treehouse-ca37057a-cff5-45b3-8415-3b02dbf6c799-per-branch-metadata -->";
return Html(content.replacen(
PER_PAGE_METADATA_REPLACEMENT_STRING,
&per_page_metadata,
// Replace one under the assumption that it appears in all pages.
1,
))
.into_response();
} else {
return (
StatusCode::INTERNAL_SERVER_ERROR,
format!("500 Internal Server Error: branch metadata points to entry {tree_path} which does not have readable content")
)
.into_response();
} }
} }
} }

View file

@ -19,8 +19,8 @@ use crate::{
fun::seasons::Season, fun::seasons::Season,
sources::Sources, sources::Sources,
vfs::{ vfs::{
self, Cd, Content, ContentCache, Dir, DynDir, Entries, HtmlCanonicalize, MemDir, Overlay, self, AnchoredAtExt, Cd, Content, ContentCache, Dir, DynDir, Entries, HtmlCanonicalize,
ToDynDir, VPath, VPathBuf, MemDir, Overlay, ToDynDir, VPath, VPathBuf,
}, },
}; };
@ -230,5 +230,7 @@ pub fn target(dirs: Arc<Dirs>, sources: Arc<Sources>) -> DynDir {
tree_view.warm_up(); tree_view.warm_up();
let tree_view = HtmlCanonicalize::new(tree_view); let tree_view = HtmlCanonicalize::new(tree_view);
Overlay::new(tree_view.to_dyn(), root.to_dyn()).to_dyn() Overlay::new(tree_view.to_dyn(), root.to_dyn())
.anchored_at(VPath::ROOT.to_owned())
.to_dyn()
} }

View file

@ -184,11 +184,7 @@ impl SemaBranch {
let attributes = Self::parse_attributes(treehouse, diagnostics, config, file_id, &branch); let attributes = Self::parse_attributes(treehouse, diagnostics, config, file_id, &branch);
let named_id = attributes.id.to_owned(); let named_id = attributes.id.to_owned();
let html_id = format!( let html_id = format!("b-{}", attributes.id);
"{}:{}",
treehouse.tree_path(file_id).unwrap(),
attributes.id
);
let redirect_here = attributes.redirect_here.clone(); let redirect_here = attributes.redirect_here.clone();

View file

@ -10,6 +10,10 @@ impl AsyncDir {
Self { inner } Self { inner }
} }
pub fn sync(&self) -> &DynDir {
&self.inner
}
pub async fn content(&self, path: &VPath) -> Option<Content> { pub async fn content(&self, path: &VPath) -> Option<Content> {
let this = self.clone(); let this = self.clone();
let path = path.to_owned(); let path = path.to_owned();

View file

@ -114,16 +114,6 @@ h1.page-title {
} }
} }
#index\:treehouse {
& > details > summary {
padding-left: 1rem;
& > th-bp {
display: none;
}
}
}
main.tree > ul { main.tree > ul {
/* Optical text offset to make the icons look less misaligned. /* Optical text offset to make the icons look less misaligned.
This is adjusted per each hobby corner to fit the icons. This is adjusted per each hobby corner to fit the icons.
@ -152,29 +142,29 @@ main.tree > ul {
} }
} }
#index\:about { #b-about {
--section-color: var(--accent-pink); --section-color: var(--accent-pink);
} }
#index\:programming { #b-programming {
--section-color: var(--accent-red); --section-color: var(--accent-red);
--section-text-offset: -0.1em; --section-text-offset: -0.1em;
} }
#index\:design { #b-design {
--section-color: var(--accent-yellow); --section-color: var(--accent-yellow);
} }
#index\:music { #b-music {
--section-color: var(--accent-green); --section-color: var(--accent-green);
--section-text-offset: -0.05em; --section-text-offset: -0.05em;
} }
#index\:games { #b-games {
--section-color: var(--accent-blue); --section-color: var(--accent-blue);
--section-text-offset: 0.05em; --section-text-offset: 0.05em;
} }
#index\:philosophy { #b-philosophy {
--section-color: var(--accent-purple); --section-color: var(--accent-purple);
} }

View file

@ -1,8 +1,7 @@
#treehouse\/issues\:issue-list>details>ul { #b-issue-list > details > ul {
/* Make issue titles bold */ /* Make issue titles bold */
&>li>details>summary>th-bc, & > li > details > summary > th-bc,
&>li>div>th-bc { & > li > div > th-bc {
--recursive-wght: 600; --recursive-wght: 600;
} }
} }

View file

@ -49,7 +49,7 @@ export class Branch {
}); });
} }
this.namedID = element.id.split(":")[1]; this.namedID = element.id.replace(/^b-/, "");
Branch.branchesByNamedID.set(this.namedID, element); Branch.branchesByNamedID.set(this.namedID, element);
if (ulid.isCanonicalUlid(this.namedID)) { if (ulid.isCanonicalUlid(this.namedID)) {

View file

@ -49,13 +49,6 @@ clever to do while browser vendors figure that out, we'll just have to do a cach
<meta property="og:site_name" content="{{ config.user.title }}"> <meta property="og:site_name" content="{{ config.user.title }}">
<meta property="og:title" content="{{ page.title }}"> <meta property="og:title" content="{{ page.title }}">
{{!--
This is a bit of a hack to quickly insert metadata into generated pages without going through Handlebars, which
would involve registering, parsing, and generating a page from a template.
Yes it would be more flexible that way, but it doesn't need to be.
It just needs to be a string replacement.
--}}
<!-- treehouse-ca37057a-cff5-45b3-8415-3b02dbf6c799-per-branch-metadata -->
{{#if page.thumbnail}} {{#if page.thumbnail}}
<meta property="og:image" content="{{ page.thumbnail.url }}"> <meta property="og:image" content="{{ page.thumbnail.url }}">
<meta property="og:image:alt" content="{{ page.thumbnail.alt }}"> <meta property="og:image:alt" content="{{ page.thumbnail.alt }}">