mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
Add default favicon.ico file (#162)
* Add default favicon.ico file * Fix typos in README.md * Move twemoji mushroom attribution * Unpack default favicon on first wiki startup Might be a bit over-engineered
This commit is contained in:
parent
5f751cca07
commit
6c25ef9085
@ -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
|
||||
}
|
||||
|
@ -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/).
|
||||
|
BIN
static/icon/mushroom.png
Normal file
BIN
static/icon/mushroom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 888 B |
Loading…
Reference in New Issue
Block a user