4 Commits

Author SHA1 Message Date
lapwat
4521497d12 add pub date to chapter skeleton 2023-10-01 22:07:38 +02:00
lapwat
2cbcf17cc2 [get] json format 2023-10-01 16:00:27 +02:00
Dei Layborer
29935be2c3 Add arm64 build actions (#14)
Add arm64 build actions for darwin/macOS and linux.
2023-09-02 11:49:35 +02:00
lapwat
a6ba42f3e1 add table of content to ebooks 2023-04-24 19:10:31 +02:00
8 changed files with 61 additions and 14 deletions

View File

@@ -9,10 +9,14 @@ jobs:
strategy: strategy:
matrix: matrix:
goos: [linux, darwin, windows] goos: [linux, darwin, windows]
goarch: [amd64, arm64]
exclude:
- goarch: arm64
goos: windows
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.30 - uses: wangyoucao577/go-release-action@v1.40
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }} goos: ${{ matrix.goos }}
goarch: amd64 goarch: ${{ matrix.goarch }}

View File

@@ -40,7 +40,9 @@ Download [latest release](https://github.com/lapwat/papeer/releases/latest) for
## MOBI support ## MOBI support
Install kindlegen to convert websites, Linux only. > Kindle e-readers now support EPUB format
Install kindlegen to export websites to Kindle compatible ebooks, Linux only.
```sh ```sh
TMPDIR=$(mktemp -d -t papeer-XXXXX) TMPDIR=$(mktemp -d -t papeer-XXXXX)

View File

@@ -127,6 +127,22 @@ func ToEpub(c chapter, filename string) string {
func AppendToEpub(e *epub.Epub, c chapter) { func AppendToEpub(e *epub.Epub, c chapter) {
content := "" content := ""
// append table of content
if len(c.SubChapters()) > 1 {
html := "<h1>Table of Contents</h1>"
html += "<ol>"
for _, sc := range c.SubChapters() {
html += fmt.Sprintf("<li>%s</li>", sc.Name())
}
html += "</ol>"
_, err := e.AddSection(html, "Table of Contents", "", "")
if err != nil {
log.Fatal(err)
}
}
// chapter content // chapter content
if c.config.Include { if c.config.Include {

View File

@@ -1,10 +1,13 @@
package book package book
import "time"
type link struct { type link struct {
Href string `json:"url"` Href string `json:"url"`
Text string `json:"name"` Text string `json:"name"`
Date *time.Time `json:"date"`
} }
func NewLink(href, text string) link { func NewLink(href, text string, date *time.Time) link {
return link{href, text} return link{href, text, date}
} }

View File

@@ -370,7 +370,7 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
log.Fatal(err) log.Fatal(err)
} }
links = append(links, NewLink(u.String(), item.Title)) links = append(links, NewLink(u.String(), item.Title, item.PublishedParsed))
} }
pathMax = "RSS" pathMax = "RSS"
@@ -405,7 +405,7 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
// if selector is set, we use the selector specified by the user // if selector is set, we use the selector specified by the user
key = selector key = selector
pathLinks[key] = append(pathLinks[key], NewLink(href, text)) pathLinks[key] = append(pathLinks[key], NewLink(href, text, &time.Time{}))
pathCount[key] += 1 pathCount[key] += 1
pathMax = key pathMax = key
@@ -419,7 +419,7 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
// we count this key if the link text is not empty // we count this key if the link text is not empty
if text != "" { if text != "" {
pathLinks[key] = append(pathLinks[key], NewLink(href, text)) pathLinks[key] = append(pathLinks[key], NewLink(href, text, &time.Time{}))
pathCount[key] += len(text) pathCount[key] += len(text)
if pathCount[key] > pathCount[pathMax] { if pathCount[key] > pathCount[pathMax] {
@@ -449,7 +449,7 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
// include home page // include home page
if include { if include {
l := NewLink(url.String(), home.Name()) l := NewLink(url.String(), home.Name(), &time.Time{})
links = append([]link{l}, links...) links = append([]link{l}, links...)
} }

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@@ -41,7 +42,7 @@ func init() {
getCmd.Flags().StringVarP(&getOpts.name, "name", "n", "", "book name (default: page title)") getCmd.Flags().StringVarP(&getOpts.name, "name", "n", "", "book name (default: page title)")
getCmd.Flags().StringVarP(&getOpts.author, "author", "a", "", "book author") getCmd.Flags().StringVarP(&getOpts.author, "author", "a", "", "book author")
getCmd.Flags().StringVarP(&getOpts.Format, "format", "f", "md", "file format [md, html, epub, mobi]") getCmd.Flags().StringVarP(&getOpts.Format, "format", "f", "md", "file format [md, json, html, epub, mobi]")
getCmd.Flags().StringVarP(&getOpts.output, "output", "", "", "file name (default: book name)") getCmd.Flags().StringVarP(&getOpts.output, "output", "", "", "file name (default: book name)")
getCmd.Flags().BoolVarP(&getOpts.stdout, "stdout", "", false, "print to standard output") getCmd.Flags().BoolVarP(&getOpts.stdout, "stdout", "", false, "print to standard output")
getCmd.Flags().BoolVarP(&getOpts.images, "images", "", false, "retrieve images only") getCmd.Flags().BoolVarP(&getOpts.images, "images", "", false, "retrieve images only")
@@ -73,6 +74,7 @@ var getCmd = &cobra.Command{
// check provided format is in list // check provided format is in list
formatEnum := map[string]bool{ formatEnum := map[string]bool{
"md": true, "md": true,
"json": true,
"html": true, "html": true,
"epub": true, "epub": true,
"mobi": true, "mobi": true,
@@ -182,6 +184,26 @@ var getCmd = &cobra.Command{
} }
} }
if getOpts.Format == "json" {
filename := book.ToMarkdown(c, getOpts.output)
bytesRead, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
book := make(map[string]interface{})
book["name"] = c.Name()
book["content"] = string(bytesRead)
bookJson, err := json.Marshal(book)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(bookJson))
}
if getOpts.Format == "html" { if getOpts.Format == "html" {
filename := book.ToHtml(c, getOpts.output) filename := book.ToHtml(c, getOpts.output)

View File

@@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Print the version number of papeer", Short: "Print the version number of papeer",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("papeer v0.7.0") fmt.Println("papeer v0.8.1")
}, },
} }