diff --git a/README.md b/README.md index da04b5e..7dddf48 100644 --- a/README.md +++ b/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. + diff --git a/main.go b/main.go index 63096ff..1dae757 100644 --- a/main.go +++ b/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 = ` +

` + article.Title + `

+

` + article.Byline + `

+
+ ` + article.Content + // store html file filename := article.Title + " - " + article.Byline out, err := os.Create(tmpDir + "/" + filename + ".html")