From ad118d8984acbe35bce1aa7c7fdd4e4aab2e74ce Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 1 Jun 2023 21:54:59 +0200 Subject: [PATCH] feat: favicon, theme color, and logs --- assets/comic.html | 2 ++ assets/favicon.ico | Bin 0 -> 2166 bytes assets/home.html | 2 ++ main.go | 44 ++++++++++++++++---------------------------- 4 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 assets/favicon.ico diff --git a/assets/comic.html b/assets/comic.html index 0349db2..2dbf768 100644 --- a/assets/comic.html +++ b/assets/comic.html @@ -3,6 +3,8 @@ {{ .Num }} - {{ .Title }} - XKCD Archive + + diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..4de1f1a55303a3632f4fc08e1e65f095ae9515a5 GIT binary patch literal 2166 zcmeHHJ5L)y5dLf*=4CdJfN>yB9LFZMA@PAPU}Ga)avLm>6e-dnA$O#M!U6;cENDO= zLybT@{sAa0U3v;6C@2u3u|$Pv5Dl5x1AMDABdoeyfj@j8+ghC;lot9Yi7#xZQ4CUS48rYYPVl2N)e4MWIkY zEEdE3{5(pf5_WfYF)%QI^Ye2I4i4h#>I%cd!#FuP!OYAI78Vwe%jIx!ae=k9HDt3{ zOiWDR^z;)7AlM?Rm&_VzaV`}?u9v;vM$y!B^NkD7_vT!sdZrva~gz84^jXD{J&;x+R_ zZD!dR|pzgfK&NN35j@}5b3xG`daH7MPq$yXPC-rq4&}~r1YdaP%eUL z!oCdQOlLXst0>-$>W*quiguu#>dT03a&%LSl1#!^=jrg&rET#gnD#fqb2dQRr0sx4 zCyDxut=^1j1@`v#aD04BvpS&WC(k^djmyi+*x1-mbBSjt&n=!=e-h1vloINKCQVH$ zOeVGN;jbUbL|8YZ<&rX&&w3Ol6D``N!^V|1cIT8;T2)MupDPMKl%F#56Yqg~#*jK( z5{A@W($WYU7B3ek(GAMV6`2~V^sG9FVpuM=*+JlXbP$IzrJz%q0H2z)==+BJ!c8b+ ztlqniRXG&Sggd{RU}CmTa;0n2FEMR8OUtXo8%&eAbCup1r*i@ uvj672n|Q90D3p%^nSA#jc2L7U0pFR(4*sbv%;x^xipq8i=r)=BFUe2A*5IxH literal 0 HcmV?d00001 diff --git a/assets/home.html b/assets/home.html index 237620f..dd0d5f7 100644 --- a/assets/home.html +++ b/assets/home.html @@ -3,6 +3,8 @@ XKCD Archive + + diff --git a/main.go b/main.go index 944eee3..17526c5 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,7 @@ var cmd = &cobra.Command{ if err != nil { return err } + log.Printf("Latest comic is %d.\n", latest) if from == 0 { from = 1 @@ -73,7 +74,7 @@ var cmd = &cobra.Command{ return err } - log.Printf("Downloading comics from %d to %d\n", from, to) + log.Printf("Downloading comics from %d to %d.\n", from, to) comicTemplate, err := getTemplate("comic") if err != nil { @@ -93,6 +94,8 @@ var cmd = &cobra.Command{ continue } + log.Printf("Downloading comic %d.\n", id) + comicDir := filepath.Join(out, fmt.Sprintf("%d", id)) metadata, err := getComic(comicDir, id) if err != nil { @@ -142,41 +145,18 @@ var cmd = &cobra.Command{ return err } - // added = added.sort((a, b) => a.num - b.num) - // await fs.outputFile(join(argv.dir, 'index.html'), homePage(added)) - - styles, err := assets.ReadFile("assets/styles.css") + err = copyAsset(out, "styles.css") if err != nil { return err } - err = os.WriteFile(filepath.Join(out, "styles.css"), styles, filePermissions) + + err = copyAsset(out, "favicon.ico") if err != nil { return err } } - // for (const info of errored) { - // const { id, dir, num } = info - // for (let i = 0; i < 3; i++) { - // try { - // const comic = await getComic(id) - // await write(comic, dir, latest) - // added.push(info) - // break - // } catch (err) { - // if (i === 2) { - // console.log(`😢 ${num} could not be fetched: ${err.toString()}`) - // } - // } - // } - // } - - // if (errored.length === 0) { - // progress('📦 All comics fetched\n') - // } else { - // progress('📦 Some comics fetched\n') - // } - + log.Println("Comics fetched.") return nil }, } @@ -201,3 +181,11 @@ func getTemplate(name string) (*template.Template, error) { } return template.New("").Parse(string(comicBytes)) } + +func copyAsset(out, filename string) error { + data, err := assets.ReadFile("assets/" + filename) + if err != nil { + return err + } + return os.WriteFile(filepath.Join(out, filename), data, filePermissions) +}