feat: favicon, theme color, and logs

This commit is contained in:
Henrique Dias 2023-06-01 21:54:59 +02:00
parent 708864997d
commit ad118d8984
No known key found for this signature in database
4 changed files with 20 additions and 28 deletions

View File

@ -3,6 +3,8 @@
<head> <head>
<title>{{ .Num }} - {{ .Title }} - XKCD Archive</title> <title>{{ .Num }} - {{ .Title }} - XKCD Archive</title>
<meta charset=utf-8> <meta charset=utf-8>
<meta name="theme-color" content="#96A8C8">
<link rel="icon" href="../favicon.ico" type="image/x-icon">
<meta name=viewport content="width=device-width,initial-scale=1"> <meta name=viewport content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex"> <meta name="robots" content="noindex">
<link rel="stylesheet" href="../styles.css"/> <link rel="stylesheet" href="../styles.css"/>

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -3,6 +3,8 @@
<head> <head>
<title>XKCD Archive</title> <title>XKCD Archive</title>
<meta charset=utf-8> <meta charset=utf-8>
<meta name="theme-color" content="#96A8C8">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
<meta name=viewport content="width=device-width,initial-scale=1"> <meta name=viewport content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex"> <meta name="robots" content="noindex">
<link rel="stylesheet" href="./styles.css"/> <link rel="stylesheet" href="./styles.css"/>

44
main.go
View File

@ -52,6 +52,7 @@ var cmd = &cobra.Command{
if err != nil { if err != nil {
return err return err
} }
log.Printf("Latest comic is %d.\n", latest)
if from == 0 { if from == 0 {
from = 1 from = 1
@ -73,7 +74,7 @@ var cmd = &cobra.Command{
return err 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") comicTemplate, err := getTemplate("comic")
if err != nil { if err != nil {
@ -93,6 +94,8 @@ var cmd = &cobra.Command{
continue continue
} }
log.Printf("Downloading comic %d.\n", id)
comicDir := filepath.Join(out, fmt.Sprintf("%d", id)) comicDir := filepath.Join(out, fmt.Sprintf("%d", id))
metadata, err := getComic(comicDir, id) metadata, err := getComic(comicDir, id)
if err != nil { if err != nil {
@ -142,41 +145,18 @@ var cmd = &cobra.Command{
return err return err
} }
// added = added.sort((a, b) => a.num - b.num) err = copyAsset(out, "styles.css")
// await fs.outputFile(join(argv.dir, 'index.html'), homePage(added))
styles, err := assets.ReadFile("assets/styles.css")
if err != nil { if err != nil {
return err return err
} }
err = os.WriteFile(filepath.Join(out, "styles.css"), styles, filePermissions)
err = copyAsset(out, "favicon.ico")
if err != nil { if err != nil {
return err return err
} }
} }
// for (const info of errored) { log.Println("Comics fetched.")
// 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')
// }
return nil return nil
}, },
} }
@ -201,3 +181,11 @@ func getTemplate(name string) (*template.Template, error) {
} }
return template.New("").Parse(string(comicBytes)) 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)
}