arnaucube
arnaucube/link2epubPublic Self-hosted repository
add cli flag for custom title, add title & author in the content init
arnaucube root@arnaucube.com
Wed, 15 Jan 2020 22:15:43 +0100
commit

19cd78ec15797fd19cb4677622fb65bc781665d8

parent

ad7cae0e1e8074784155dc7d67631feda113b342

2 files changed, 24 insertions(+), 4 deletions(-)

jump to
M README.md → 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 @@

## 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. +
M main.go → main.go

@@ -15,12 +15,13 @@

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()

@@ -69,6 +70,17 @@

// replace in the article.Content the current img by new filename 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