make emojis cached
This commit is contained in:
parent
c337d38891
commit
f3aee8f41a
|
@ -1,5 +1,3 @@
|
||||||
mod static_urls;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
|
@ -16,7 +14,6 @@ use copy_dir::copy_dir;
|
||||||
use handlebars::{handlebars_helper, Handlebars};
|
use handlebars::{handlebars_helper, Handlebars};
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use static_urls::StaticUrls;
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -29,6 +26,7 @@ use crate::{
|
||||||
tree::branches_to_html,
|
tree::branches_to_html,
|
||||||
},
|
},
|
||||||
state::Source,
|
state::Source,
|
||||||
|
static_urls::StaticUrls,
|
||||||
tree::SemaRoots,
|
tree::SemaRoots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -215,7 +213,13 @@ impl Generator {
|
||||||
parsed_trees: Vec<ParsedTree>,
|
parsed_trees: Vec<ParsedTree>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
let mut config_derived_data = ConfigDerivedData::default();
|
let mut config_derived_data = ConfigDerivedData {
|
||||||
|
image_sizes: Default::default(),
|
||||||
|
static_urls: StaticUrls::new(
|
||||||
|
paths.static_dir.to_owned(),
|
||||||
|
format!("{}/static", config.site),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
handlebars_helper!(cat: |a: String, b: String| a + &b);
|
handlebars_helper!(cat: |a: String, b: String| a + &b);
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,12 @@ use log::{debug, error, warn};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::html::highlight::{
|
use crate::{
|
||||||
compiled::{compile_syntax, CompiledSyntax},
|
html::highlight::{
|
||||||
Syntax,
|
compiled::{compile_syntax, CompiledSyntax},
|
||||||
|
Syntax,
|
||||||
|
},
|
||||||
|
static_urls::StaticUrls,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
@ -179,9 +182,9 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data derived from the config.
|
/// Data derived from the config.
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct ConfigDerivedData {
|
pub struct ConfigDerivedData {
|
||||||
pub image_sizes: HashMap<String, Option<ImageSize>>,
|
pub image_sizes: HashMap<String, Option<ImageSize>>,
|
||||||
|
pub static_urls: StaticUrls,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Image size. This is useful for emitting <img> elements with a specific size to eliminate
|
/// Image size. This is useful for emitting <img> elements with a specific size to eliminate
|
||||||
|
|
|
@ -555,9 +555,12 @@ where
|
||||||
.write_str("<img data-cast=\"emoji\" title=\":")?;
|
.write_str("<img data-cast=\"emoji\" title=\":")?;
|
||||||
escape_html(&mut self.writer, name)?;
|
escape_html(&mut self.writer, name)?;
|
||||||
self.writer.write_str(":\" src=\"")?;
|
self.writer.write_str(":\" src=\"")?;
|
||||||
escape_html(&mut self.writer, &self.config.site)?;
|
let url = self
|
||||||
self.writer.write_str("/static/emoji/")?;
|
.config_derived_data
|
||||||
escape_html(&mut self.writer, filename)?;
|
.static_urls
|
||||||
|
.get(&format!("emoji/{filename}"))
|
||||||
|
.unwrap_or_default();
|
||||||
|
escape_html(&mut self.writer, &url)?;
|
||||||
self.writer.write_str("\" alt=\"")?;
|
self.writer.write_str("\" alt=\"")?;
|
||||||
escape_html(&mut self.writer, name)?;
|
escape_html(&mut self.writer, name)?;
|
||||||
if let Some(image_size) = self
|
if let Some(image_size) = self
|
||||||
|
|
|
@ -142,6 +142,9 @@ pub fn branch_to_html(
|
||||||
"page" => Some((config.page_url(linked).into(), "".into())),
|
"page" => Some((config.page_url(linked).into(), "".into())),
|
||||||
"pic" => config.pics.get(linked).map(|filename| {
|
"pic" => config.pics.get(linked).map(|filename| {
|
||||||
(
|
(
|
||||||
|
// NOTE: We can't generate a URL with a hash here yet, because we
|
||||||
|
// cannot access ConfigDerivedData here due to it being borrowed
|
||||||
|
// by the Markdown parser.
|
||||||
format!("{}/static/pic/{}", config.site, &filename).into(),
|
format!("{}/static/pic/{}", config.site, &filename).into(),
|
||||||
"".into(),
|
"".into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,6 +16,7 @@ mod fun;
|
||||||
mod html;
|
mod html;
|
||||||
mod paths;
|
mod paths;
|
||||||
mod state;
|
mod state;
|
||||||
|
mod static_urls;
|
||||||
mod tree;
|
mod tree;
|
||||||
|
|
||||||
async fn fallible_main() -> anyhow::Result<()> {
|
async fn fallible_main() -> anyhow::Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue