Skip to content

Commit e962a17

Browse files
authored
Merge pull request #40 from m4salah/cusome-404-github-page
Custome 404 GitHub page
2 parents 974fda7 + 69d9f1b commit e962a17

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

build.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ func buildStaticSite(dest string) error {
5656
}
5757
})
5858

59+
// If we render 404 page
60+
// Copy 404 page from dest/404/index.html to /dest/404.html
61+
if in, err := os.Open(path.Join(dest, NOT_FOUND_PAGE, "index.html")); err == nil {
62+
defer in.Close()
63+
out, err := os.Create(path.Join(dest, "404.html"))
64+
if err != nil {
65+
log.Printf("error while opening dest/404.html, err: %s", err.Error())
66+
}
67+
defer out.Close()
68+
io.Copy(out, in)
69+
}
70+
5971
for route := range extension_page_enclosed {
6072
err := buildRoute(
6173
srv,

docs/404.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This usually means that you've typed or followed a bad URL. Occasionally, this can happen if the page has been moved to a new URL (though we try to avoid doing that).
2+
3+
See [the Wikipedia page on HTTP 404 errors](https://en.wikipedia.org/wiki/HTTP_404) to learn more about HTTP 404 errors in general.

flags.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
)
77

88
var (
9-
SOURCE string // path to markdown files directory
10-
BUILD string // path to write built files
11-
READONLY bool // is xlog in readonly mode
12-
SITENAME string // name of knowledgebase
13-
SIDEBAR bool // is sidebar displayed
14-
INDEX string // name of the index page markdown file
9+
SOURCE string // path to markdown files directory
10+
BUILD string // path to write built files
11+
READONLY bool // is xlog in readonly mode
12+
SITENAME string // name of knowledgebase
13+
SIDEBAR bool // is sidebar displayed
14+
INDEX string // name of the index page markdown file
15+
NOT_FOUND_PAGE string // name of the index page markdown file
1516
)
1617

1718
func init() {
@@ -23,6 +24,7 @@ func init() {
2324
flag.StringVar(&BUILD, "build", "", "Build all pages as static site in this directory")
2425
flag.StringVar(&SITENAME, "sitename", "XLOG", "Site name is the name that appears on the header beside the logo and in the title tag")
2526
flag.StringVar(&INDEX, "index", "index", "Index file name used as home page")
27+
flag.StringVar(&NOT_FOUND_PAGE, "notfoundpage", "404", "Custom not found page")
2628
flag.BoolVar(&READONLY, "readonly", false, "Should xlog hide write operations, read-only means all write operations will be disabled")
2729
flag.BoolVar(&SIDEBAR, "sidebar", true, "Should render sidebar.")
2830
}

0 commit comments

Comments
 (0)