Compare commits

..

No commits in common. "9125738498759e6a7fe188331829b065bcfed758" and "e555f437c7c23170f2e653c23117f4c6f45644a5" have entirely different histories.

7 changed files with 559 additions and 527 deletions

976
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,42 +1,47 @@
[package]
description = "static site generator fit for a dog"
edition = "2024"
edition = "2021"
homepage = "https://webdog.zyl.gay"
license = "AGPL-3.0-or-later"
name = "webdog"
readme = "README.md"
repository = "https://github.com/zyllian/webdog"
version = "0.1.3"
version = "0.1.1"
[dependencies]
clap = { version = "4", features = ["derive"] }
color-eyre = { version = "0.6", optional = true }
clap = {version = "4", features = ["derive"]}
color-eyre = {version = "0.6", optional = true}
extract-frontmatter = "4"
eyre = "0.6"
futures = { version = "0.3", optional = true }
grass = { version = "0.13", default-features = false }
hotwatch = { version = "0.5", optional = true }
html5ever = "0.31"
fs_extra = "1.2"
futures = {version = "0.3", optional = true}
grass = {version = "0.13", default-features = false}
hotwatch = {version = "0.5", optional = true}
html5ever = "0.29"
include_dir = "0.7"
kuchikiki = "0.8.8-speedreader"
itertools = "0.14"
kuchikiki = "0.8.6-speedreader"
lol_html = "2"
minifier = { version = "0.3", features = ["html"] }
percent-encoding = { version = "2", optional = true }
pulldown-cmark = { version = "0.13", default-features = false, features = [
minifier = {version = "0.3", features = ["html"]}
percent-encoding = {version = "2", optional = true}
pulldown-cmark = {version = "0.12", default-features = false, features = [
"simd",
"html",
] }
]}
rayon = "1"
rss = { version = "2", features = ["validation"] }
serde = { version = "1", features = ["derive"] }
rss = {version = "2", features = ["validation"]}
serde = {version = "1", features = ["derive"]}
serde_yaml_ng = "0.10"
syntect = "5"
tera = "1"
time = { version = "0.3", features = ["serde-human-readable"] }
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
url = { version = "2", features = ["serde"] }
time = {version = "0.3", features = ["serde-human-readable"]}
tokio = {version = "1", features = [
"macros",
"rt-multi-thread",
], optional = true}
url = {version = "2", features = ["serde"]}
walkdir = "2"
warp = { version = "0.3", optional = true }
warp = {version = "0.3", optional = true}
[features]
default = ["serve", "color-eyre"]

View file

@ -37,10 +37,6 @@ list of sass/scss stylesheets in the site's `sass` directory to treat as root st
base url for the various cdn url transformation features of webdog.
## `webdog_path`
optional custom path for webdog's static resources.
## `code_theme`
the theme to use for code blocks. valid options: `base16-ocean.dark`, `base16-eighties.dark`, `base16-mocha.dark`, `base16-ocean.light`, `InspiredGitHub`, `Solarized (dark)`, and `Solarized (light)`

View file

@ -2,18 +2,18 @@
use std::{collections::HashMap, path::PathBuf};
use eyre::{Context, OptionExt, eyre};
use lol_html::{HtmlRewriter, Settings, element, html_content::ContentType};
use eyre::{eyre, Context, OptionExt};
use lol_html::{element, html_content::ContentType, HtmlRewriter, Settings};
use rayon::prelude::*;
use serde::Serialize;
use syntect::{highlighting::ThemeSet, parsing::SyntaxSet};
use tera::Tera;
use url::Url;
use crate::{PageMetadata, ROOT_PATH, SASS_PATH, Site, resource::ResourceBuilder, util};
use crate::{resource::ResourceBuilder, util, PageMetadata, Site, ROOT_PATH, SASS_PATH};
/// Default path for static webdog resources included with the site build.
const WEBDOG_DEFAULT_PATH: &str = "webdog";
/// Path for static webdog resources included with the site build.
const WEBDOG_PATH: &str = "webdog";
/// Struct containing data to be sent to templates when rendering them.
#[derive(Debug, Serialize)]
@ -96,13 +96,7 @@ impl SiteBuilder {
std::fs::create_dir(&self.build_path).wrap_err("Failed to create build directory")?;
}
let webdog_path = self.build_path.join(
self.site
.config
.webdog_path
.clone()
.unwrap_or_else(|| WEBDOG_DEFAULT_PATH.to_string()),
);
let webdog_path = self.build_path.join(WEBDOG_PATH);
std::fs::create_dir(&webdog_path)?;
std::fs::write(
webdog_path.join("webdog.js"),
@ -161,7 +155,6 @@ impl SiteBuilder {
}
/// Function to rewrite HTML wow.
#[allow(clippy::too_many_arguments)]
pub fn rewrite_html(
&self,
html: String,
@ -170,7 +163,6 @@ impl SiteBuilder {
scripts: &[String],
styles: &[String],
is_partial: bool,
webdog_path: &str,
) -> eyre::Result<String> {
use kuchikiki::traits::*;
@ -259,9 +251,7 @@ impl SiteBuilder {
);
}
el.append(
&format!(
r#"<script type="text/javascript" src="/{webdog_path}/webdog.js" defer></script>"#
),
r#"<script type="text/javascript" src="/webdog/webdog.js" defer></script>"#,
ContentType::Html,
);
if self.serving {
@ -387,12 +377,6 @@ impl SiteBuilder {
&page_metadata.scripts,
&page_metadata.styles,
page_metadata.is_partial,
&self
.site
.config
.webdog_path
.clone()
.unwrap_or_else(|| WEBDOG_DEFAULT_PATH.to_string()),
)?;
if let Some(data) = extra {

View file

@ -1,4 +1,5 @@
use lol_html::{RewriteStrSettings, element};
use itertools::Itertools;
use lol_html::{element, RewriteStrSettings};
use serde::{Deserialize, Serialize};
use crate::{builder::SiteBuilder, resource::ResourceTemplateData};
@ -110,12 +111,10 @@ fn resource_list_outside(
)
.map(|ts| (id, v, ts))
})
.map(|v| {
v.map(|(id, v, ts)| ResourceTemplateData {
resource: v,
id: id.clone(),
readable_timestamp: ts,
})
.map_ok(|(id, v, ts)| ResourceTemplateData {
resource: v,
id: id.clone(),
readable_timestamp: ts,
})
.collect::<eyre::Result<Vec<_>>>()?,
})?,

View file

@ -49,8 +49,6 @@ pub struct SiteConfig {
pub sass_styles: Vec<PathBuf>,
/// URL to the CDN used for the site's images.
pub cdn_url: Url,
/// The path to output webdog static resources to. Defaults to "webdog"
pub webdog_path: Option<String>,
/// The theme to use for the site's code blocks.
/// TODO: dark/light themes
/// TODO: export themes as CSS instead of styling HTML directly
@ -75,7 +73,6 @@ impl SiteConfig {
build: None,
sass_styles: vec!["index.scss".into()],
cdn_url,
webdog_path: None,
code_theme: "base16-ocean.dark".to_string(),
resources: Default::default(),
}

View file

@ -4,16 +4,17 @@ use std::{
};
use eyre::Context;
use rss::{ChannelBuilder, ItemBuilder, validation::Validate};
use itertools::Itertools;
use rss::{validation::Validate, ChannelBuilder, ItemBuilder};
use serde::{Deserialize, Serialize};
use time::{OffsetDateTime, format_description::well_known::Rfc2822};
use time::{format_description::well_known::Rfc2822, OffsetDateTime};
use crate::{
PageMetadata,
builder::SiteBuilder,
frontmatter::FrontMatterRequired,
link_list::Link,
util::{self, format_timestamp},
PageMetadata,
};
/// Metadata for resources.
@ -318,7 +319,7 @@ impl ResourceBuilder {
let page_max = list.len() / items_per_page + (list.len() % items_per_page).min(1);
let mut previous = None;
let mut next;
for (page, iter) in list.chunks(items_per_page).enumerate() {
for (page, iter) in list.iter().chunks(items_per_page).into_iter().enumerate() {
next = (page + 1 != page_max).then_some(page + 2);
let out = builder.build_page_raw(
PageMetadata {
@ -328,7 +329,7 @@ impl ResourceBuilder {
},
"",
ResourceListTemplateData {
resources: iter.to_vec(),
resources: iter.copied().collect(),
tag,
rss_enabled: config.rss.is_some(),
page: page + 1,
@ -371,7 +372,7 @@ impl ResourceBuilder {
// Build list of tags
{
let mut links: Vec<_> = tags
let links = tags
.iter()
.map(|(tag, data)| {
let count = data.len();
@ -383,9 +384,9 @@ impl ResourceBuilder {
count,
)
})
.sorted_by(|(_, a), (_, b)| b.cmp(a))
.map(|(l, _)| l)
.collect();
links.sort_by(|(_, a), (_, b)| b.cmp(a));
let links = links.into_iter().map(|(l, _)| l).collect();
let out = crate::link_list::render_basic_link_list(
builder,
&self.config.tag_list_template,