mirror of
https://github.com/arnaucube/link2epub.git
synced 2026-02-06 19:16:42 +01:00
add cli flag for custom title, add title & author in the content init
This commit is contained in:
14
README.md
14
README.md
@@ -1,6 +1,8 @@
|
||||
# link2epub [](https://goreportcard.com/report/github.com/arnaucube/link2epub)
|
||||
Very simple tool to download articles and convert it to `.epub`/`.mobi` files.
|
||||
|
||||
It gets the text content, simplifies its html, downloads the images, and builds the `.epub`/`.mobi` file.
|
||||
|
||||
## Download
|
||||
- Binary can be:
|
||||
- downloaded from [releases section](https://github.com/arnaucube/link2epub/releases)
|
||||
@@ -9,12 +11,18 @@ Very simple tool to download articles and convert it to `.epub`/`.mobi` files.
|
||||
## Usage
|
||||
Needs [calibre](https://calibre-ebook.com/) in order to convert to `.epub` and `.mobi`.
|
||||
|
||||
Putting the binary in the `~/bin` directory will be more comfortable.
|
||||
|
||||
```bash
|
||||
./link2epub -l https://link.com/to-the-article
|
||||
link2epub -l https://link.com/to-the-article
|
||||
|
||||
// optionally add extension (by default .mobi)
|
||||
./link2epub -l https://link.com/to-the-article -type mobi
|
||||
./link2epub -l https://link.com/to-the-article -type epub
|
||||
link2epub -l https://link.com/to-the-article -type mobi
|
||||
link2epub -l https://link.com/to-the-article -type epub
|
||||
|
||||
// see help for all the available flags
|
||||
link2epub --help
|
||||
```
|
||||
|
||||
Thanks to [@dhole](https://github.com/dhole) for the advisment.
|
||||
|
||||
|
||||
14
main.go
14
main.go
@@ -15,12 +15,13 @@ import (
|
||||
readability "github.com/go-shiori/go-readability"
|
||||
)
|
||||
|
||||
const tmpDir = "tmp"
|
||||
const tmpDir = "link2epubtmpdir"
|
||||
|
||||
func main() {
|
||||
// var typeFlag string
|
||||
linkFlag := flag.String("l", "", "Link to download")
|
||||
typeFlag := flag.String("type", "mobi", "Type of epub. Available: mobi (default), epub")
|
||||
titleFlag := flag.String("title", "", "Title is automatically getted from article, if want to change it, use this flag")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@@ -70,6 +71,17 @@ func main() {
|
||||
article.Content = strings.Replace(article.Content, string(img[4]), filename, -1)
|
||||
}
|
||||
|
||||
if *titleFlag != "" {
|
||||
article.Title = *titleFlag
|
||||
}
|
||||
|
||||
// add title to content
|
||||
article.Content = `
|
||||
<h1>` + article.Title + `</h1>
|
||||
<h2 style="text-align:right;">` + article.Byline + `</h2>
|
||||
<br>
|
||||
` + article.Content
|
||||
|
||||
// store html file
|
||||
filename := article.Title + " - " + article.Byline
|
||||
out, err := os.Create(tmpDir + "/" + filename + ".html")
|
||||
|
||||
Reference in New Issue
Block a user