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:
parent
70be482fb7
commit
c537eb844f
8 changed files with 26 additions and 66 deletions
|
@ -23,7 +23,7 @@ use tracing::{info, instrument};
|
|||
use crate::dirs::Dirs;
|
||||
use crate::sources::Sources;
|
||||
use crate::vfs::asynch::AsyncDir;
|
||||
use crate::vfs::VPath;
|
||||
use crate::vfs::{self, VPath};
|
||||
use crate::{html::EscapeHtml, state::Source};
|
||||
|
||||
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 {
|
||||
let branch = state.sources.treehouse.tree.branch(branch_id);
|
||||
if let Source::Tree { input, tree_path } =
|
||||
state.sources.treehouse.source(branch.file_id)
|
||||
{
|
||||
if let Some(content) = state
|
||||
.target
|
||||
.content(tree_path)
|
||||
.await
|
||||
.and_then(|c| c.string().ok())
|
||||
if let Source::Tree { tree_path, .. } = state.sources.treehouse.source(branch.file_id) {
|
||||
if let Some(url) =
|
||||
vfs::url(&state.sources.config.site, &state.target.sync(), tree_path)
|
||||
{
|
||||
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();
|
||||
let url = format!("{url}#{}", branch.html_id);
|
||||
return (StatusCode::FOUND, [(LOCATION, url)]).into_response();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ use crate::{
|
|||
fun::seasons::Season,
|
||||
sources::Sources,
|
||||
vfs::{
|
||||
self, Cd, Content, ContentCache, Dir, DynDir, Entries, HtmlCanonicalize, MemDir, Overlay,
|
||||
ToDynDir, VPath, VPathBuf,
|
||||
self, AnchoredAtExt, Cd, Content, ContentCache, Dir, DynDir, Entries, HtmlCanonicalize,
|
||||
MemDir, Overlay, ToDynDir, VPath, VPathBuf,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -230,5 +230,7 @@ pub fn target(dirs: Arc<Dirs>, sources: Arc<Sources>) -> DynDir {
|
|||
tree_view.warm_up();
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -184,11 +184,7 @@ impl SemaBranch {
|
|||
let attributes = Self::parse_attributes(treehouse, diagnostics, config, file_id, &branch);
|
||||
|
||||
let named_id = attributes.id.to_owned();
|
||||
let html_id = format!(
|
||||
"{}:{}",
|
||||
treehouse.tree_path(file_id).unwrap(),
|
||||
attributes.id
|
||||
);
|
||||
let html_id = format!("b-{}", attributes.id);
|
||||
|
||||
let redirect_here = attributes.redirect_here.clone();
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ impl AsyncDir {
|
|||
Self { inner }
|
||||
}
|
||||
|
||||
pub fn sync(&self) -> &DynDir {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub async fn content(&self, path: &VPath) -> Option<Content> {
|
||||
let this = self.clone();
|
||||
let path = path.to_owned();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue