Add strikethrough support
This commit is contained in:
parent
ff605ada27
commit
9eb0935369
|
@ -141,7 +141,7 @@ I don't think there's any consensus (nor any built-in way) on how to include doc
|
|||
:::
|
||||
```
|
||||
|
||||
- Other metadata can be included through `config` blocks. There's no required fields as of now, and some fields are implied by other fields (i.e. `hidden` implies `sitemap_exclude`). Moreover, not all metadata is stored in the file itself. Properties like the `last_changed` date are taken directly from git!
|
||||
- Other metadata can be included through `config` blocks. There's no required fields as of now, and some fields are implied by other fields (i.e. `hidden` implies `sitemap_exclude`). Moreover, not all metadata is stored in the file itself. Properties like the `last_changed` date are taken directly from Git!
|
||||
|
||||
````djot
|
||||
{ role=config }
|
||||
|
@ -155,6 +155,20 @@ I don't think there's any consensus (nor any built-in way) on how to include doc
|
|||
```
|
||||
````
|
||||
|
||||
## Tracking modification dates
|
||||
|
||||
You might've noticed that every article (including this one!) not only shows the creation date of the post at hand, but that of its last edit as well. There are different ways one could approach implementing something like this:
|
||||
|
||||
- Getting the date directly from the filesystem. While simple in concept, there's a myriad of issues that come packaged with this idea — the fact it's not portable over Git is already a deal breaker for me.
|
||||
|
||||
- Storing the modification date within the metadata of the post itself (i.e. inside the `.dj` file), and updating it manually on each edit. While easy to implement, this solution is too prone to uhhhh, me forgetting to bump up the date on each edit.
|
||||
|
||||
- Automatically getting the last modification date from Git, and storing it inside the metadata. This is the solution I decided to go with, although issues arose along the way.
|
||||
|
||||
As there's no "official" way to store metadata inside `djot` files (and I'm using my own home-brewed format), modifying the metadata programatically would be a bit hacky, and hence something I avoided. I instead store all the last modification dates inside a [file][moonythm-last-modifications-file] at the root of the repo. "But wait, if you're getting the dates from Git, why store them in the first place?", I hear you ask. I too, thought I wouldn't at first. It didn't take long ([that's a lie, it took me forever]{ role="strike" }) for me to realise I couldn't access the `.git` directory inside Nix derivations, as that would introduce possible impurities (i.e. access to dangling branches and whatnot), and is thus something Nix makes very hard to do in the first place.
|
||||
|
||||
[moonythm-last-modifications-file]: https://git.moonythm.dev/prescientmoon/moonythm/src/branch/main/last_modified.toml
|
||||
|
||||
## Further work
|
||||
|
||||
There's quite a few things this website is missing. Here's a non-exhausting list:
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
buildInputs = with pkgs; [ ];
|
||||
|
||||
MOONYTYM_DRAFTS = 1;
|
||||
MOONYTHM_DRAFTS = 1;
|
||||
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -6,5 +6,7 @@ runCommand "moonythm" { } ''
|
|||
mkdir $out
|
||||
|
||||
cd ${../.}
|
||||
|
||||
export MOONYTHM_BASE_URL="https://moonythm.dev"
|
||||
MOONYTHM_OUT_DIR="$out" ${moonythm-generator}/bin/moonythm
|
||||
''
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct Pages<'a> {
|
|||
|
||||
content_root: PathBuf,
|
||||
out_root: PathBuf,
|
||||
base_url: &'a str,
|
||||
base_url: String,
|
||||
}
|
||||
|
||||
impl<'a> Pages<'a> {
|
||||
|
@ -31,7 +31,8 @@ impl<'a> Pages<'a> {
|
|||
assets: Vec::new(),
|
||||
content_root,
|
||||
out_root,
|
||||
base_url: "http://localhost:8080",
|
||||
base_url: std::env::var("MOONYTHM_BASE_URL")
|
||||
.unwrap_or_else(|_| "http://localhost:8080".to_owned()),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ impl<'a> Pages<'a> {
|
|||
page_renderer.feed(&mut out, |label, out| {
|
||||
match label {
|
||||
"title" => {
|
||||
let mut w = crate::html::Writer::new(page, &[], self.base_url);
|
||||
let mut w = crate::html::Writer::new(page, &[], &self.base_url);
|
||||
w.states.push(crate::html::State::TextOnly);
|
||||
|
||||
for event in &page.title.events {
|
||||
|
@ -99,7 +100,7 @@ impl<'a> Pages<'a> {
|
|||
}
|
||||
}
|
||||
"description" => {
|
||||
let mut w = crate::html::Writer::new(page, &[], self.base_url);
|
||||
let mut w = crate::html::Writer::new(page, &[], &self.base_url);
|
||||
w.states.push(crate::html::State::TextOnly);
|
||||
|
||||
for event in &page.description {
|
||||
|
@ -115,7 +116,7 @@ impl<'a> Pages<'a> {
|
|||
)?;
|
||||
}
|
||||
"content" => {
|
||||
let mut w = crate::html::Writer::new(page, &self.pages, self.base_url);
|
||||
let mut w = crate::html::Writer::new(page, &self.pages, &self.base_url);
|
||||
|
||||
for event in jotdown::Parser::new(page.source) {
|
||||
w.render_event(&event, out)?;
|
||||
|
|
|
@ -43,6 +43,7 @@ pub enum State<'s> {
|
|||
Ignore,
|
||||
Raw,
|
||||
Figure,
|
||||
Strikethrough,
|
||||
Math(bool),
|
||||
CodeBlock(String),
|
||||
Aside(TemplateRenderer<'s>),
|
||||
|
@ -466,6 +467,9 @@ impl<'s> Writer<'s> {
|
|||
self.states.push(State::Datetime(String::new()))
|
||||
} else if has_role(attrs, "date") {
|
||||
self.states.push(State::Date(String::new()))
|
||||
} else if has_role(attrs, "strike") {
|
||||
self.states.push(State::Strikethrough);
|
||||
out.write_str("<s>")?
|
||||
} else {
|
||||
out.write_str("<span>")?
|
||||
}
|
||||
|
@ -721,6 +725,8 @@ impl<'s> Writer<'s> {
|
|||
date.format("%Y-%m-%d"),
|
||||
date.format("%a, %d %b %Y")
|
||||
)?;
|
||||
} else if matches!(self.states.last(), Some(State::Strikethrough)) {
|
||||
out.write_str("</s>")?;
|
||||
} else {
|
||||
out.write_str("</span>")?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue