summary history branches tags files
commit:fe81abfdac33a53b7446b6abbc0a610978879d62
author:Trevor Bentley
committer:Trevor Bentley
date:Wed Jan 15 00:01:36 2025 +0100
parents:a99f2a72a3bfc09be4d8b0e8dd1cea12837403af
copy readme files to their real name in addition to the file hash
diff --git a/src/generate.rs b/src/generate.rs
line changes: +17/-0
index e6826f6..b81e2a4
--- a/src/generate.rs
+++ b/src/generate.rs
@@ -889,6 +889,23 @@ impl GitsyGenerator {
                                 local_bytes = self.write_rendered(&out_path, &rendered);
                                 atomic_repo_bytes.fetch_add(local_bytes, Ordering::SeqCst);
                                 atomic_bytes.fetch_add(local_bytes, Ordering::SeqCst);
+
+                                // Copy readme files to their real filename, so links to readme files remain valid
+                                // across file changes.
+                                if let Some(readmes) = &repo_desc.readme_files {
+                                    for readme in readmes {
+                                        if &file.path == readme {
+                                            let mut pretty_path = PathBuf::from(out_path);
+                                            pretty_path.pop();
+                                            pretty_path.push(&file.path);
+                                            match std::fs::copy(&out_path, &pretty_path) {
+                                                Ok(_) => louder!(" - wrote readme file: {}", pretty_path.to_string_lossy()),
+                                                Err(e) => error!("ERROR: {:?}", e),
+                                            }
+                                        }
+                                    }
+                                };
+
                             }
                             Err(x) => match x.kind {
                                 _ => error!("ERROR: {:?}", x),

diff --git a/templates/default_dark/summary.html b/templates/default_dark/summary.html
line changes: +2/-2
index a8ac5ce..6cffc6a
--- a/templates/default_dark/summary.html
+++ b/templates/default_dark/summary.html
@@ -11,7 +11,7 @@
   <tr class="readme">
     <td class="field website">Documentation:</td>
     {% if readme and readme.id in file_ids -%}
-    <td class="value website"><a href="{{repo_url | safe}}/{{readme.kind}}/{{readme.id}}.html">{{readme.name | default(value="[none]")}}</a></td>
+    <td class="value website"><a href="{{repo_url | safe}}/{{readme.kind}}/{{readme.name}}.html">{{readme.name | default(value="[none]")}}</a></td>
     {% else -%}
     <td class="value website">{{readme.name | default(value="[none]")}}</td>
     {% endif -%}
@@ -19,7 +19,7 @@
   <tr class="website">
     <td class="field website">Website:</td>
     {% if metadata.website -%}
-    <td class="value website"><a href="{{ metadata.website }}">{{metadata.website | default(value="[none]")}}</a></td>
+    <td class="value website"><a href="{{ metadata.website | safe }}">{{metadata.website | default(value="[none]")}}</a></td>
     {% else -%}
     <td class="value website">{{metadata.website | default(value="[none]")}}</td>
     {% endif-%}

diff --git a/templates/default_light/summary.html b/templates/default_light/summary.html
line changes: +2/-2
index a8ac5ce..41172aa
--- a/templates/default_light/summary.html
+++ b/templates/default_light/summary.html
@@ -11,7 +11,7 @@
   <tr class="readme">
     <td class="field website">Documentation:</td>
     {% if readme and readme.id in file_ids -%}
-    <td class="value website"><a href="{{repo_url | safe}}/{{readme.kind}}/{{readme.id}}.html">{{readme.name | default(value="[none]")}}</a></td>
+    <td class="value website"><a href="{{repo_url | safe}}/{{readme.kind}}/{{readme.name}}">{{readme.name | default(value="[none]")}}</a></td>
     {% else -%}
     <td class="value website">{{readme.name | default(value="[none]")}}</td>
     {% endif -%}
@@ -19,7 +19,7 @@
   <tr class="website">
     <td class="field website">Website:</td>
     {% if metadata.website -%}
-    <td class="value website"><a href="{{ metadata.website }}">{{metadata.website | default(value="[none]")}}</a></td>
+    <td class="value website"><a href="{{ metadata.website | safe }}">{{metadata.website | default(value="[none]")}}</a></td>
     {% else -%}
     <td class="value website">{{metadata.website | default(value="[none]")}}</td>
     {% endif-%}