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 0000000..4de1f1a Binary files /dev/null and b/assets/favicon.ico differ 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) +}