Repos / s4g / 50e15ee562
commit 50e15ee562d2d4bfe2fea8aef7995334ad4912f3
Author: Nhân <hi@imnhan.com>
Date: Sun Jul 9 20:33:36 2023 +0700
clean up WebPath (trim index.html suffix)
diff --git a/feed.go b/feed.go
index ed45e21..9dc9e1e 100644
--- a/feed.go
+++ b/feed.go
@@ -17,8 +17,8 @@ func generateFeed(site SiteMetadata, posts []Article, path string) []byte {
var entries []*atom.Entry
for _, p := range posts {
entries = append(entries, &atom.Entry{
- ID: siteAddr + p.WebPath,
- Link: []atom.Link{{Href: siteAddr + p.WebPath}},
+ ID: siteAddr + p.WebPath(),
+ Link: []atom.Link{{Href: siteAddr + p.WebPath()}},
Title: p.Title,
Published: atom.Time(p.PostedAt),
Updated: atom.Time(p.PostedAt),
diff --git a/main.go b/main.go
index c4f9c04..f034930 100644
--- a/main.go
+++ b/main.go
@@ -116,7 +116,7 @@ func regenerate(fsys writablefs.FS) {
for _, a := range articles {
fmt.Println(">", a.Path, "-", a.Title)
a.WriteHtmlFile(&site, articlesInNav, startYear)
- generatedFiles[a.WebPath] = true
+ generatedFiles[a.OutputPath] = true
}
fmt.Printf("Processed %d articles\n", len(articles))
@@ -169,10 +169,10 @@ func readSiteMetadata(fsys writablefs.FS) SiteMetadata {
}
type Article struct {
- Fs writablefs.FS
- Path string
- WebPath string
- DjotBody string
+ Fs writablefs.FS
+ Path string
+ OutputPath string
+ DjotBody string
ArticleMetadata
}
@@ -185,6 +185,14 @@ type ArticleMetadata struct {
ShowInNav bool
}
+func (a *Article) WebPath() string {
+ p := a.OutputPath
+ if strings.HasSuffix(p, "/index.html") {
+ p = strings.TrimSuffix(p, "index.html")
+ }
+ return p
+}
+
func (a *Article) WriteHtmlFile(
site *SiteMetadata,
articlesInNav []Article,
@@ -223,7 +231,7 @@ func (a *Article) WriteHtmlFile(
fullHtml := buf.Bytes()
// Now write into an html with the same name as the original djot file
- err = a.Fs.WriteFile(a.WebPath, fullHtml)
+ err = a.Fs.WriteFile(a.OutputPath, fullHtml)
if err != nil {
panic(err)
}
@@ -301,7 +309,7 @@ func findArticles(fsys writablefs.FS) (result []Article) {
article := Article{
Fs: fsys,
Path: path,
- WebPath: strings.TrimSuffix(path, DjotExt) + ".html",
+ OutputPath: strings.TrimSuffix(path, DjotExt) + ".html",
DjotBody: bodyText,
ArticleMetadata: meta,
}
diff --git a/www/about/index.html b/www/about/index.html
index 7eefe28..f1f52cf 100644
--- a/www/about/index.html
+++ b/www/about/index.html
@@ -14,7 +14,7 @@
<nav>
<a href="/">Home</a>
- <a href="/about/index.html">About</a>
+ <a href="/about/">About</a>
</nav>
diff --git a/www/feed.xml b/www/feed.xml
index df876fb..59e37b0 100644
--- a/www/feed.xml
+++ b/www/feed.xml
@@ -17,8 +17,8 @@
</entry>
<entry>
<title>Hello</title>
- <id>https://coolzone.example.com/hello/index.html</id>
- <link href="https://coolzone.example.com/hello/index.html"></link>
+ <id>https://coolzone.example.com/hello/</id>
+ <link href="https://coolzone.example.com/hello/"></link>
<published>2022-01-02T00:00:00+07:00</published>
<updated>2022-01-02T00:00:00+07:00</updated>
</entry>
diff --git a/www/hello/index.html b/www/hello/index.html
index f9c85c7..a2df623 100644
--- a/www/hello/index.html
+++ b/www/hello/index.html
@@ -14,7 +14,7 @@
<nav>
<a href="/">Home</a>
- <a href="/about/index.html">About</a>
+ <a href="/about/">About</a>
<span class="posted-on">
Posted on
<time datetime="2022-01-02">
diff --git a/www/index.html b/www/index.html
index add5104..4ce2c50 100644
--- a/www/index.html
+++ b/www/index.html
@@ -20,7 +20,7 @@ <h1 class="site-title">CoolZone</h1>
<div class="pages">
<a href="/">Home</a>
- <a href="about/index.html">About</a>
+ <a href="about/">About</a>
<a class="feed-link" href="/feed.xml">
<img src="/_theme/feed.svg" alt="Atom Feed" title="Atom Feed">
</a>
@@ -37,7 +37,7 @@ <h1 class="site-title">CoolZone</h1>
</li>
<li>
2022-01-02 —
- <a href="hello/index.html">Hello</a>
+ <a href="hello/">Hello</a>
</li>
</ul>
diff --git a/www/mfws.html b/www/mfws.html
index 83eb6c9..dd9cd83 100644
--- a/www/mfws.html
+++ b/www/mfws.html
@@ -14,7 +14,7 @@
<nav>
<a href="/">Home</a>
- <a href="/about/index.html">About</a>
+ <a href="/about/">About</a>
<span class="posted-on">
Posted on
<time datetime="2023-04-05">