From 8f2a49f7a9a5d7e6208aa12d94b749b4a66b26e5 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sat, 15 Jun 2024 23:04:07 -0700
Subject: [PATCH] Add a <base> for all relative links

---
 .gitlab-ci.yml      |  1 +
 src/cache-test.html |  3 ++-
 src/index.html      |  3 ++-
 src/sub/index.html  | 15 ++++++++-------
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1aaa27f..d879434 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -41,6 +41,7 @@ setup:
     - find src/ -type f -name '*.html'
       -exec sed -i
         -e "s|%%BRANCH%%|${CI_COMMIT_BRANCH}|g"
+        -e "s|%%BASE_URL%%|${CI_PAGES_URL}/|g"
         -e "s|%%COMMIT_SHA%%|${CI_COMMIT_SHORT_SHA}|g"
         -e "s|%%COMMIT_TIMESTAMP%%|${CI_COMMIT_TIMESTAMP}|g"
         -e "s|%%JOB_ID%%|${CI_JOB_ID}|g"
diff --git a/src/cache-test.html b/src/cache-test.html
index a60c97d..c435732 100644
--- a/src/cache-test.html
+++ b/src/cache-test.html
@@ -2,9 +2,10 @@
 <html lang="en">
 <head>
   <meta charset="utf-8">
+  <base href="%%BASE_URL%%">
+  <title>Cache Test | %%PROJECT_TITLE%%</title>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="generator" content="GitLab Pages">
-  <title>Cache Test | %%PROJECT_TITLE%%</title>
   <link rel="shortcut icon" href="gitlab-favicon.png">
   <link rel="preload" href="style.css" as="style">
   <link rel="stylesheet" href="style.css">
diff --git a/src/index.html b/src/index.html
index 118ee3b..368a6da 100644
--- a/src/index.html
+++ b/src/index.html
@@ -2,9 +2,10 @@
 <html lang="en">
 <head>
   <meta charset="utf-8">
+  <base href="%%BASE_URL%%">
+  <title>%%PROJECT_TITLE%%</title>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="generator" content="GitLab Pages">
-  <title>%%PROJECT_TITLE%%</title>
   <link rel="shortcut icon" href="gitlab-favicon.png">
   <link rel="preload" href="style.css" as="style">
   <link rel="stylesheet" href="style.css">
diff --git a/src/sub/index.html b/src/sub/index.html
index 6350dbd..4cf21a8 100644
--- a/src/sub/index.html
+++ b/src/sub/index.html
@@ -2,18 +2,19 @@
 <html lang="en">
 <head>
   <meta charset="utf-8">
+  <base href="%%BASE_URL%%">
+  <title>Subdirectory | %%PROJECT_TITLE%%</title>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="generator" content="GitLab Pages">
-  <title>Subdirectory | %%PROJECT_TITLE%%</title>
-  <link rel="shortcut icon" href="../gitlab-favicon.png">
-  <link rel="preload" href="../style.css" as="style">
-  <link rel="stylesheet" href="../style.css">
+  <link rel="shortcut icon" href="gitlab-favicon.png">
+  <link rel="preload" href="style.css" as="style">
+  <link rel="stylesheet" href="style.css">
 </head>
 <body>
   <header>
-    <a href="../">Homepage</a>
-    <a href="../cache-test.html">Cache Test</a>
-    <a href="./">Subdirectory</a>
+    <a href="./">Homepage</a>
+    <a href="cache-test.html">Cache Test</a>
+    <a href="sub/">Subdirectory</a>
     <a href="%%PROJECT_URL%%">Repository</a>
   </header>
   <main>
-- 
GitLab