feat: link to file in footer

This commit is contained in:
Maciej Jur 2024-05-02 15:26:08 +02:00
parent 7d8e959db5
commit 0f4cd3ca20
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
11 changed files with 54 additions and 90 deletions

View file

@ -1,65 +0,0 @@
---
title: Writing code considered harmful
date: 2023-06-14T22:09:06.127Z
---
When I initially delved into programming, I held the belief that it revolved solely around composing sets of instructions for the computer to execute. At a glance, it indeed appeared as such - merely commanding the computer to carry out tasks in a predetermined sequence, with the anticipation of obtaining a desirable outcome. This perception was further reinforced when observing how computers interpret code in assembly language, where each step is executed in a specific order within the CPU.
However, my view gradually changed as I was studying computer science at an university. First it was the object-oriented programming, which showed me the importance of choosing the right high level abstractions for a given problem. It started to seem to me as if programming was more about composing such abstractions to make problems easier to solve and easier to modify as needs change :cite[gamma1994design].
I also once thought that mathematics are not that important when it comes to computer science. I remember that at the start I had linear algebra and calculus courses, but I didn't really enjoy them much. Back then I didn't really understand the value of mathematics in this context, I just thought that they were things I had to pass on the way to „real” programming. To my horror it never seemed to end! It just became more subtly embedded within what I was doing all around.
For instance, statistics, and linear algebra, turned out to be the key to understanding machine learning. Without sufficient knowledge in that area of mathematics you can't really grasp how machine learning works on the fundamental level :cite[chollet2021deep]. It was at that point that I regretted not having worked harder at my linear algebra foundations.
A highlight of my studies was when I had a functional programming course, which felt like a U-turn probably on everything I learned up until that point. Suddenly, mutability was a bad thing, and everything was a function. I had to give up living in the object-oriented world. At that point I realized that there is in fact a different way to write software, and it's one deeply connected with nothing other than - mathematics. Okay.
Functional programming has the additional advantage over imperative and object-oriented paradigms that its abstractions are founded in mathematics. In fact, you can even write your programs using denotational demantics, which essentially means that code is more or less equivalent to mathematical equations. You can prove the program is correct by proving that the mathematical equivalent of it is :cite[10.1145/360303.360308].
It's really powerful.
## Summary
It was a pretty fun and interesting adventure, difficult at times, but worth it over all. In hindsight, I regret not paying more attention to mathematics right from the start. If I were to start over I would probably focus more on that and the theory of computation. If you're only just starting out then please remember, writing code is not computer science :cat:
## Bibliography
:::bibtex
@book{gamma1994design,
title = {Design Patterns: Elements of Reusable Object-Oriented Software},
author = {Gamma, E. and Helm, R. and Johnson, R. and Vlissides, J.},
isbn = {9780321700698},
lccn = {94034264},
series = {Addison-Wesley Professional Computing Series},
year = {1994},
publisher = {Pearson Education}
}
@book{chollet2021deep,
title = {Deep Learning with Python, Second Edition},
author = {Chollet, F.},
isbn = {9781617296864},
lccn = {2021425412},
year = {2021},
publisher = {Manning}
}
@article{10.1145/360303.360308,
author = {Tennent, R. D.},
title = {The Denotational Semantics of Programming Languages},
year = {1976},
issue_date = {Aug. 1976},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {19},
number = {8},
issn = {0001-0782},
url = {https://doi.org/10.1145/360303.360308},
doi = {10.1145/360303.360308},
journal = {Commun. ACM},
month = {aug},
pages = {437453},
numpages = {17},
keywords = {semantics, GEDANKEN, store, environment, LOOP, continuation, applicative, higher-order function, imperative, programming language, theory of computation, recursive definition}
}
:::

View file

@ -137,7 +137,11 @@ fn to_source(path: Utf8PathBuf, exts: &HashSet<&'static str>) -> FileItem {
pub fn render_all(items: &[Output]) {
for item in items {
render(item, &Sack::new(items, &item.path));
let file = match &item.kind {
OutputKind::Real(a) => Some(&a.meta.path),
OutputKind::Fake(_) => None,
};
render(item, &Sack::new(items, &item.path, file));
}
}

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use camino::Utf8PathBuf;
use camino::{Utf8Path, Utf8PathBuf};
use hayagriva::Library;
use crate::html::{Link, LinkDate, Linkable};
@ -41,11 +41,13 @@ pub struct Sack<'a> {
hole: &'a [Output],
/// Current path for page
path: &'a Utf8PathBuf,
/// Original file location
file: Option<&'a Utf8PathBuf>,
}
impl<'a> Sack<'a> {
pub fn new(hole: &'a [Output], path: &'a Utf8PathBuf) -> Self {
Self { hole, path }
pub fn new(hole: &'a [Output], path: &'a Utf8PathBuf, file: Option<&'a Utf8PathBuf>) -> Self {
Self { hole, path, file }
}
pub fn get_links(&self, path: &str) -> Vec<LinkDate> {
@ -96,4 +98,14 @@ impl<'a> Sack<'a> {
_ => None,
})
}
/// Get the path for output
pub fn get_path(&self) -> &'a Utf8Path {
self.path.as_path()
}
/// Get the path for original file location
pub fn get_file(&self) -> Option<&'a Utf8Path> {
self.file.map(Utf8PathBuf::as_ref)
}
}

View file

@ -1,3 +1,4 @@
use camino::Utf8Path;
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
use crate::REPO;
@ -81,11 +82,15 @@ pub fn navbar() -> impl Renderable {
)
}
pub fn footer() -> impl Renderable {
pub fn footer(path: Option<&Utf8Path>) -> impl Renderable {
let copy = format!("Copyright &copy; {} Maciej Jur", &REPO.year);
let mail = "maciej@kamoshi.org";
let href = format!("mailto:{}", mail);
let repo = format!("{}/tree/{}", &REPO.link, &REPO.hash);
let link = Utf8Path::new(&REPO.link).join("tree").join(&REPO.hash);
let link = match path {
Some(path) => link.join(path),
None => link,
};
maud_move!(
footer .footer {
@ -98,7 +103,7 @@ pub fn footer() -> impl Renderable {
}
}
div .repo {
a href=(repo) {
a href=(link.as_str()) {
(&REPO.hash)
}
div {

View file

@ -73,5 +73,5 @@ pub fn home<'data, 'home, R>(main: R) -> impl Renderable + 'home
}
);
page("Home", main)
page("Home", main, None)
}

View file

@ -45,7 +45,7 @@ pub fn list<'data, 'list>(
}
);
page(title, list)
page(title, list, None)
}
fn section(year: i32, group: &[LinkDate]) -> impl Renderable + '_ {

View file

@ -1,3 +1,4 @@
use camino::Utf8Path;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use crate::html::base::{head, navbar, footer};
@ -19,10 +20,14 @@ pub fn bare<'data, 'html, R>(title: &'data str, main: R) -> impl Renderable + 'h
)
}
pub fn page<'data, 'main, 'page, T>(title: &'data str, main: T) -> impl Renderable + 'page
pub fn page<'data, 'main, 'html, T>(
title: &'data str,
main: T,
path: Option<&'data Utf8Path>,
) -> impl Renderable + 'html
where
'main : 'page,
'data : 'page,
'main : 'html,
'data : 'html,
T: Renderable + 'main
{
maud_move!(
@ -33,7 +38,7 @@ pub fn page<'data, 'main, 'page, T>(title: &'data str, main: T) -> impl Renderab
body {
(navbar())
(main)
(footer())
(footer(path))
}
}
)

View file

@ -1,21 +1,24 @@
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
use crate::gen::Sack;
use crate::html::misc::{show_bibliography, show_outline};
use crate::html::page;
use crate::md::Post;
use crate::text::md::Outline;
pub fn post<'fm, 'md, 'post, T>(
fm: &'fm Post,
pub fn post<'f, 'm, 's, 'html, T>(
fm: &'f Post,
content: T,
outline: Outline,
bib: Option<Vec<String>>,
) -> impl Renderable + 'post
sack: &'s Sack,
) -> impl Renderable + 'html
where
'fm: 'post,
'md: 'post,
T: Renderable + 'md
'f: 'html,
'm: 'html,
's: 'html,
T: Renderable + 'm
{
let main = maud_move!(
main .wiki-main {
@ -46,5 +49,5 @@ pub fn post<'fm, 'md, 'post, T>(
}
);
page(&fm.title, main)
page(&fm.title, main, sack.get_file())
}

View file

@ -12,7 +12,7 @@ pub fn map() -> impl Renderable {
(Raw("import 'photos';"))
}
}
))
), None)
}
pub fn search() -> impl Renderable {
@ -20,5 +20,5 @@ pub fn search() -> impl Renderable {
main {
}
))
), None)
}

View file

@ -53,5 +53,5 @@ pub fn wiki<'data, 'html, 'sack, T>(
}
);
page(&fm.title, main)
page(&fm.title, main, sack.get_file())
}

View file

@ -57,7 +57,7 @@ impl Content for md::Post {
&'f self,
content: T,
outline: Outline,
_: &'s Sack,
sack: &'s Sack,
bib: Option<Vec<String>>,
) -> impl Renderable + 'html
where
@ -65,7 +65,7 @@ impl Content for md::Post {
'm: 'html,
's: 'html,
T: Renderable + 'm {
html::post(self, content, outline, bib)
html::post(self, content, outline, bib, sack)
}
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {