Skip to content

Commit b6d1f37

Browse files
Merge pull request #860: Add Netlify clean routes and dynamic footer links
2 parents 92d323a + 90f1577 commit b6d1f37

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

‎build_netlify.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ def build_html() -> None:
5656
target_file.write_text(rewrite_html(content), encoding="utf-8")
5757

5858

59+
def write_clean_route_redirects() -> None:
60+
redirects = [
61+
"/chat /chat.html 200",
62+
"/auth /auth.html 200",
63+
"/library /library.html 200",
64+
"/vault /vault.html 200",
65+
"/profile /profile.html 200",
66+
"/privacy-policy /privacy-policy.html 200",
67+
"/terms-and-conditions /terms-and-conditions.html 200",
68+
"/request-book /request-book.html 200",
69+
]
70+
(DIST / "_redirects").write_text("\n".join(redirects) + "\n", encoding="utf-8")
71+
72+
5973
def inject_api_base_override() -> None:
6074
"""Optional Netlify build env MOOD_API_BASE → runtime override in dist config.js."""
6175
api_base = os.getenv("MOOD_API_BASE", "").strip()
@@ -79,8 +93,9 @@ def main() -> None:
7993
shutil.copy2(manifest_src, DIST / "manifest.json")
8094

8195
build_html()
96+
write_clean_route_redirects()
8297
inject_api_base_override()
8398

8499

85100
if __name__ == "__main__":
86-
main()
101+
main()

‎frontend/js/footer.js‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
const createFooter = () => {
22
const year = new Date().getFullYear();
3+
const pagePath = (page) => {
4+
const isLocalPreview = window.location.protocol === 'file:' ||
5+
['localhost', '127.0.0.1', ''].includes(window.location.hostname);
6+
const cleanPath = page === 'index' ? '/' : `/${page}`;
7+
const htmlPath = `${page}.html`;
8+
9+
return isLocalPreview ? htmlPath : cleanPath;
10+
};
311

412
const footerHTML = `
513
<footer class="main-footer">
614
<div class="footer-container">
715
<!-- Brand Section -->
816
<div class="footer-brand">
9-
<a href="index.html" class="logo" aria-label="BiblioDrift Home">
17+
<a href="${pagePath('index')}" class="logo" aria-label="BiblioDrift Home">
1018
<img class="footer-logo" src="../assets/images/biblioDrift_favicon.png" alt="BiblioDrift Logo"> BiblioDrift
1119
</a>
1220
<p class="footer-tagline">"There is no frigate like a book to take us lands away."</p>
@@ -17,23 +25,24 @@ const createFooter = () => {
1725
<nav class="footer-nav" aria-label="Footer Navigation">
1826
<h3>Explore</h3>
1927
<ul>
20-
<li><a href="index.html">Discovery</a></li>
21-
<li><a href="vault.html">My Vault</a></li>
22-
<li><a href="library.html">My Library</a></li>
23-
<li><a href="chat.html">Literary Chat</a></li>
24-
<li><a href="auth.html">Account</a></li>
28+
<li><a href="${pagePath('index')}">Discovery</a></li>
29+
<li><a href="${pagePath('vault')}">My Vault</a></li>
30+
<li><a href="${pagePath('library')}">My Library</a></li>
31+
<li><a href="${pagePath('chat')}">Literary Chat</a></li>
32+
<li><a href="${pagePath('auth')}">Account</a></li>
2533
<li>
26-
<a href="https://github.com/devanshi14malhotra/BiblioDrift" target="_blank">
27-
Repository
28-
</a>
29-
</ul>
34+
<a href="https://github.com/devanshi14malhotra/BiblioDrift" target="_blank" rel="noopener noreferrer">
35+
Repository
36+
</a>
37+
</li>
38+
</ul>
3039
</nav>
3140
3241
<div class="footer-legal">
3342
<h3>Legal</h3>
3443
<ul>
35-
<li><a href="privacy-policy.html">Privacy Policy</a></li>
36-
<li><a href="terms-and-conditions.html">Terms & Conditions</a></li>
44+
<li><a href="${pagePath('privacy-policy')}">Privacy Policy</a></li>
45+
<li><a href="${pagePath('terms-and-conditions')}">Terms & Conditions</a></li>
3746
</ul>
3847
</div>
3948

0 commit comments

Comments
 (0)