yagit

Yet another static site generator for Git 🙀️

Commit
712b755bf8f09dd1a6a7acbae53b839aa9e544bd
Parent
eacf64df7016d33f8e8a2f8f3b949b47fcd8b5ad
Author
Pablo <pablo-pie@riseup.net>
Date

Improved the accessibility of different feeds

Also locked dependency versions

Diffstats

2 files changed, 38 insertions, 26 deletions

Status Name Changes Insertions Deletions
Modified Cargo.toml 2 files changed 5 5
Modified src/main.rs 2 files changed 33 21
diff --git a/Cargo.toml b/Cargo.toml
@@ -6,13 +6,13 @@ description = "Yet another static site generator for Git"
 build = "build.rs"
 
 [dependencies]
-git2 = "0.20.0"
-libc = "0.2.170"
-pulldown-cmark = { version = "0.13.0", features = ["simd"] }
-static-toml = "1.3.0"
+git2 = "=0.20.0"
+libc = "=0.2.170"
+pulldown-cmark = { version = "=0.13.0", features = ["simd"] }
+static-toml = "=1.3.0"
 
 [build-dependencies]
-static-toml = "1.3.0"
+static-toml = "=1.3.0"
 
 [profile.release]
 debug = true
diff --git a/src/main.rs b/src/main.rs
@@ -696,9 +696,13 @@ impl<'repo> RepoRenderer<'repo> {
     let mut f = create_file(index_path)?;
 
     self.render_header(&mut f, PageTitle::Log { repo_name: self.name })?;
-    writeln!(&mut f, "<div class=\"article-list\">")?;
 
-    for commit in &commits {
+    // NOTE: see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/feed_role
+    let n_commits = commits.len();
+    writeln!(&mut f, "<div id=\"commits-feed\" class=\"article-list\" role=\"feed\" aria-busy=\"false\">")?;
+
+    for (i, commit) in commits.iter().enumerate() {
+      let i = i+1;
       let commit_sig = commit.author();
 
       let author = commit_sig.name().unwrap();
@@ -714,20 +718,19 @@ impl<'repo> RepoRenderer<'repo> {
       // already allocates under the rug
       let shorthand_id = &format!("{}", id)[..8];
 
-      writeln!(&mut f, "<article>")?;
-      writeln!(&mut f, "<div>")?;
-      writeln!(
-        &mut f,
-        "<span class=\"commit-heading\"><a href=\"/{root}{name}/{COMMIT_SUBDIR}/{id}.html\">{shorthand_id}</a> &mdash; {author}</span>",
-        root = self.output_root,
-        name = Escaped(self.name),
-      )?;
+      writeln!(&mut f, "<article aria-posinset=\"{i}\" aria-setsize=\"{n_commits}\" aria-labelledby=\"{shorthand_id}-label\" aria-describedby=\"{shorthand_id}-description\">")?;
+
+      writeln!(&mut f, "<div id=\"{shorthand_id}-label\" class=\"commit-heading\">")?;
+      writeln!(&mut f, "<a href=\"/{root}{name}/{COMMIT_SUBDIR}/{id}.html\">{shorthand_id}</a> &mdash; {author}",
+                       root = self.output_root, name = Escaped(self.name))?;
+      writeln!(&mut f, "</div>")?;
       writeln!(&mut f, "<time datetime=\"{datetime}\">{date}</time>",
                        datetime  = DateTime(time), date = Date(time))?;
-      writeln!(&mut f, "</div>")?;
-      writeln!(&mut f, "<p>")?;
+
+      writeln!(&mut f, "<p id=\"{shorthand_id}-description\">")?;
       writeln!(&mut f, "{msg}", msg = Escaped(msg))?;
       writeln!(&mut f, "</p>")?;
+
       writeln!(&mut f, "</article>")?;
     }
 
@@ -1390,16 +1393,23 @@ fn render_index(repos: &[RepoInfo], private: bool) -> io::Result<()> {
   // ==========================================================================
   render_header(&mut f, PageTitle::Index)?;
   writeln!(&mut f, "<main>")?;
-  writeln!(&mut f, "<div class=\"article-list\">")?;
 
-  for repo in repos {
-    writeln!(&mut f, "<article>")?;
+  // NOTE: see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/feed_role
+  let n_repos = repos.len();
+  writeln!(&mut f, "<div class=\"article-list\" role=\"feed\" aria-busy=\"false\">")?;
+  for (i, repo) in repos.iter().enumerate() {
+    let i = i+1;
+    write!(&mut f, "<article aria-postinset=\"{i}\" aria-setsize=\"{n_repos}\" aria-labelledby=\"{i}-label\"")?;
+    if repo.description.is_some() {
+      writeln!(&mut f, " aria-describedby=\"{i}-description\">")?;
+    } else {
+      writeln!(&mut f, ">")?;
+    }
 
-    writeln!(&mut f, "<h4>")?;
-    writeln!(&mut f, "<a href=\"/{root}{repo}/index.html\">{repo}</a>",
-                     root = output_root,
-                     repo = Escaped(&repo.name))?;
-    writeln!(&mut f, "</h4>")?;
+    writeln!(&mut f, "<div id=\"{i}-label\" class=\"repo-heading\">")?;
+    writeln!(&mut f, "<a href=\"/{root}{repo}/\">{repo}</a>",
+                     root = output_root, repo = Escaped(&repo.name))?;
+    writeln!(&mut f, "</div>")?;
 
     writeln!(&mut f, "<div>")?;
     writeln!(&mut f, "<time datetime=\"{datetime}\">{date}</time>",
@@ -1408,15 +1418,17 @@ fn render_index(repos: &[RepoInfo], private: bool) -> io::Result<()> {
     writeln!(&mut f, "</div>")?;
 
     if let Some(ref description) = repo.description {
+      writeln!(&mut f, "<div id=\"{i}-description\">")?;
       for p in description.trim().split("\n\n") {
         writeln!(&mut f, "<p>\n{p}\n</p>", p = p.trim())?;
       }
+      writeln!(&mut f, "</div>")?;
     }
 
     writeln!(&mut f, "</article>")?;
   }
-
   writeln!(&mut f, "</div>")?;
+
   writeln!(&mut f, "</main>")?;
   render_footer(&mut f)?;
   writeln!(&mut f, "</body>")?;