From 6c25ef908559301c7066197e873fa4321316932f Mon Sep 17 00:00:00 2001 From: opsyne <85858658+opsyne@users.noreply.github.com> Date: Mon, 22 Aug 2022 01:31:17 -0700 Subject: [PATCH] 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 --- files/files.go | 42 +++++++++++++++++++++++++++++++++++++++ static/icon/README.md | 3 +++ static/icon/mushroom.png | Bin 0 -> 888 bytes 3 files changed, 45 insertions(+) create mode 100644 static/icon/mushroom.png 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 0000000000000000000000000000000000000000..80402a0cc1101f84d77380b06abdbd08627bf12a GIT binary patch literal 888 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAk#x&WULSN8&+yLvA8(F42S*EM~g z7jOQudKXaTL)R#XdLZ{*&)ny!6+p&4Gw&y%nIEPsc@|p$-Qtmb^F$RB5cUnhPfGR)O5cXE89^<(vo z!(pC0^$UfzES;%#DY9#6z`^xZC%%~ey-=&;YMWs$p)@&5>xGE6Gpp_#j-5SPlGhe7 zxG4WJo3|w6Qpm-OSB(i#?`;mB>f!mJH09dLmp}8l&#G}RTDik7_h#MJ%75=ey809E ziM>%34NHie?0f#nm-8z(wTaKxHJlkS!Ps}|TQ(o-tO;JaMv8~|c(k*O91k`X>G)J< znYc0Tz42~g$%3>KA5Ix%Kk#_3>*9W5uE&HV<4rPaI1Gz6=vGcSH&=Ytgr`jRm4tNG zh^a>Tq?I~e`y#rJrDAbf`D)kK8x6MKHezTHn0{qV{+5i~n_v7n80;P`-YWO=-=7}4 zhE4ZUPCgf$`EkWUCieYzI-|QRXDK{y=)P~XDYfXT&V<*E?e_0JtvjOdys>}hPRWmj z@o#hz73DW<(s|{X?tf$*x8j18|7+}mx0J+pOm4ngt7!RmuJ|L?o3)BNT_rvQsF~|N zZfrIx>?zx(KLs!$ZUbxYjiteugM)ze9iIT$^lM2Eh&u$ zi&iyqb-!P$W3+z435T2=X?yZka-ZCF(b^$J!AwfBKX+RDw%KwYwsl|I|NEje8w-!; r>s=S38)jdyJvM9e8q4cD9<#Z-^DJsRvu!#sK{9x{`njxgN@xNAOwPOo literal 0 HcmV?d00001