Skip to content
Snippets Groups Projects
Commit 7174967b authored by Stephen D's avatar Stephen D
Browse files

page ordering via indexes

parent f9e180a1
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ a:visited {
img, video {
max-width: 100%;
max-width: 100%;
max-height: 100%;
}
th, td {
......
......@@ -36,9 +36,6 @@ impl Blog {
}
fn home(&mut self) -> Result<String, Error> {
self.posts.sort();
self.posts.reverse();
let mut content =
r#"<div class="centered"><h1>Stephen's Site</h1></div>Welcome to my corner of the Internet. Occasionally I will do something kind of interesting and post about it here. Bear with me - I'm a developer, not a writer, so I'm bad at keeping this place up to date! For a more complete list of my work, please check out my <a href="https://gitlab.scd31.com/stephen">Git repository</a>.<h2>Recent Posts</h2><table>"#
.to_string();
......@@ -76,6 +73,9 @@ impl TryFrom<Blog> for RenderedBlog {
type Error = Error;
fn try_from(mut b: Blog) -> Result<Self, Error> {
b.pages.sort();
b.posts.sort();
let mut pages = HashMap::new();
for p in &b.posts {
......@@ -159,6 +159,6 @@ fn dress_page(title: &str, content: &str, pages: &[Post], favicon: &Option<Favic
}
format!(
r#"<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/style.css" />{favicons}<title>{title}</title></head><body><div><a href="/">Home</a>{page_links}<img src="img/logo.png" class="align-right" /></div><hr>{content}</body></html>"#
r#"<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/style.css" />{favicons}<title>{title}</title></head><body><div><a href="/">Home</a>{page_links}<img src="/img/logo.png" class="align-right" /></div><hr>{content}</body></html>"#
)
}
......@@ -74,7 +74,7 @@ impl Favicon {
}
pub fn html(&self) -> &'static str {
r#"<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"><link rel="shortcut icon" href="favicon.ico">
r#"<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="shortcut icon" href="/favicon.ico">
"#
}
}
......@@ -15,6 +15,7 @@ use crate::{
pub struct Post {
pub title: String,
pub date: Option<Date>,
pub index: u32,
pub content: String,
pub url: String,
}
......@@ -88,7 +89,12 @@ impl Loadable for Post {
impl Ord for Post {
fn cmp(&self, other: &Self) -> Ordering {
self.date.cmp(&other.date)
let mut o = self.index.cmp(&other.index);
if o.is_eq() {
o = self.date.cmp(&other.date).reverse();
}
o
}
}
......@@ -100,13 +106,14 @@ impl PartialOrd for Post {
impl PartialEq for Post {
fn eq(&self, other: &Self) -> bool {
self.date == other.date
self.index == other.index && self.date == other.date
}
}
struct PostParser {
title: Option<String>,
date: Option<Date>,
index: Option<u32>,
url: String,
content: Vec<u8>,
handler: CustomHtmlHandler,
......@@ -117,6 +124,7 @@ impl PostParser {
Ok(Self {
title: None,
date: None,
index: None,
url,
content: vec![],
handler: CustomHtmlHandler::new()?,
......@@ -143,6 +151,14 @@ impl Parser<Post> for PostParser {
self.date = Some(parse_org_date(value)?);
}
Element::Keyword(Keyword { key, value, .. }) if key == "INDEX" => {
if self.index.is_some() {
bail!("Post has more than one index");
}
self.index = Some(value.parse()?);
}
_ => {
self.handler.start(&mut self.content, e)?;
}
......@@ -160,12 +176,14 @@ impl Parser<Post> for PostParser {
fn render(self) -> anyhow::Result<Post> {
let title = self.title.context("Could not find post title")?;
let date = self.date;
let index = self.index.unwrap_or(u32::MAX);
let content = String::from_utf8(self.content)?;
let url = self.url;
Ok(Post {
title,
date,
index,
content,
url,
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment