diff --git a/files/files.go b/files/files.go index 32824a5..97cafb4 100644 --- a/files/files.go +++ b/files/files.go @@ -2,10 +2,12 @@ package files import ( + "io" "os" "path/filepath" "github.com/bouncepaw/mycorrhiza/cfg" + "github.com/bouncepaw/mycorrhiza/static" ) var paths struct { @@ -51,6 +53,10 @@ func InterwikiJSON() string { return paths.interwikiJSON } // PrepareWikiRoot ensures all needed directories and files exist and have // correct permissions. func PrepareWikiRoot() error { + isFirstInit := false + if _, err := os.Stat(cfg.WikiDir); err != nil && os.IsNotExist(err) { + isFirstInit = true + } if err := os.MkdirAll(cfg.WikiDir, os.ModeDir|0777); err != nil { return err } @@ -77,5 +83,41 @@ func PrepareWikiRoot() error { paths.categoriesJSON = filepath.Join(cfg.WikiDir, "categories.json") paths.interwikiJSON = FileInRoot("interwiki.json") + // Are we initializing the wiki for the first time? + if isFirstInit { + err := firstTimeInit() + if err != nil { + return err + } + } + + return nil +} + +// firstTimeInit takes care of any tasks that only need to happen the first time the wiki is initialized +func firstTimeInit() error { + static.InitFS(StaticFiles()) + + defaultFavicon, err := static.FS.Open("icon/mushroom.png") + if err != nil { + return err + } + + defer defaultFavicon.Close() + + outputFileName := filepath.Join(cfg.WikiDir, "static", "favicon.ico") + + outputFile, err := os.Create(outputFileName) + if err != nil { + return err + } + + defer outputFile.Close() + + _, err = io.Copy(outputFile, defaultFavicon) + if err != nil { + return err + } + return nil } diff --git a/static/icon/README.md b/static/icon/README.md index 676093a..be56320 100644 --- a/static/icon/README.md +++ b/static/icon/README.md @@ -8,3 +8,6 @@ This is a modified version of https://www.svgrepo.com/svg/232085/rat. #### `feed` This one is from https://upload.wikimedia.org/wikipedia/commons/4/46/Generic_Feed-icon.svg. + +#### `mushroom` +This is the [mushroom emoji](https://github.com/twitter/twemoji/blob/54df6a1/assets/72x72/1f344.png) from Twitter's [twemoji project](https://twemoji.twitter.com/), and is licensed under the [Creative Commons CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). diff --git a/static/icon/mushroom.png b/static/icon/mushroom.png new file mode 100644 index 0000000..80402a0 Binary files /dev/null and b/static/icon/mushroom.png differ