Browse Source

add cli flag for custom title, add title & author in the content init

master v0.0.2
arnaucube 5 years ago
parent
commit
19cd78ec15
2 changed files with 24 additions and 4 deletions
  1. +11
    -3
      README.md
  2. +13
    -1
      main.go

+ 11
- 3
README.md

@ -1,6 +1,8 @@
# link2epub [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucube/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.

+ 13
- 1
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")

Loading…
Cancel
Save