From 2cbcf17cc2097847503ce605db87a26970a2e2a5 Mon Sep 17 00:00:00 2001 From: lapwat Date: Sun, 1 Oct 2023 16:00:27 +0200 Subject: [PATCH] [get] json format --- .github/workflows/release.yml | 2 +- README.md | 4 +++- book/scraper_test.go | 2 +- cmd/get.go | 24 +++++++++++++++++++++++- cmd/version.go | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81c67c3..6f7ad1d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: goos: windows steps: - uses: actions/checkout@v3 - - uses: wangyoucao577/go-release-action@v1.30 + - uses: wangyoucao577/go-release-action@v1.40 with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} diff --git a/README.md b/README.md index 2bb4d44..6536436 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ Download [latest release](https://github.com/lapwat/papeer/releases/latest) for ## 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 TMPDIR=$(mktemp -d -t papeer-XXXXX) diff --git a/book/scraper_test.go b/book/scraper_test.go index 911c17e..6068ca0 100644 --- a/book/scraper_test.go +++ b/book/scraper_test.go @@ -11,7 +11,7 @@ func TestBody(t *testing.T) { c := NewChapterFromURL("https://12factor.net/", "", []*ScrapeConfig{config}, 0, func(index int, name string) {}) got := c.Body() - want := "\n\n\n \n\n The Twelve-Factor App \n \n \n\n \n \n\n \n \n\n \n \n\n\n \n\n
\n

The Twelve-Factor App

\n
\n\n
\n
\n

Introduction

\n\n

In the modern era, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps that:

\n\n
    \n
  • Use declarative formats for setup automation, to minimize time and cost for new developers joining the project;
  • \n\n
  • Have a clean contract with the underlying operating system, offering maximum portability between execution environments;
  • \n\n
  • Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration;
  • \n\n
  • Minimize divergence between development and production, enabling continuous deployment for maximum agility;
  • \n\n
  • And can scale up without significant changes to tooling, architecture, or development practices.
  • \n
\n\n

The twelve-factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).

\n
\n
\n

Background

\n\n

The contributors to this document have been directly involved in the development and deployment of hundreds of apps, and indirectly witnessed the development, operation, and scaling of hundreds of thousands of apps via our work on the Heroku platform.

\n\n

This document synthesizes all of our experience and observations on a wide variety of software-as-a-service apps in the wild. It is a triangulation on ideal practices for app development, paying particular attention to the dynamics of the organic growth of an app over time, the dynamics of collaboration between developers working on the app’s codebase, and avoiding the cost of software erosion.

\n\n

Our motivation is to raise awareness of some systemic problems we’ve seen in modern application development, to provide a shared vocabulary for discussing those problems, and to offer a set of broad conceptual solutions to those problems with accompanying terminology. The format is inspired by Martin Fowler’s books Patterns of Enterprise Application Architecture and Refactoring.

\n
\n
\n

Who should read this document?

\n\n

Any developer building applications which run as a service. Ops engineers who deploy or manage such applications.

\n
\n
\n\n
\n
\n

The Twelve Factors

\n\n

I. Codebase

\n\n

One codebase tracked in revision control, many deploys

\n\n

II. Dependencies

\n\n

Explicitly declare and isolate dependencies

\n\n

III. Config

\n\n

Store config in the environment

\n\n

IV. Backing services

\n\n

Treat backing services as attached resources

\n\n

V. Build, release, run

\n\n

Strictly separate build and run stages

\n\n

VI. Processes

\n\n

Execute the app as one or more stateless processes

\n\n

VII. Port binding

\n\n

Export services via port binding

\n\n

VIII. Concurrency

\n\n

Scale out via the process model

\n\n

IX. Disposability

\n\n

Maximize robustness with fast startup and graceful shutdown

\n\n

X. Dev/prod parity

\n\n

Keep development, staging, and production as similar as possible

\n\n

XI. Logs

\n\n

Treat logs as event streams

\n\n

XII. Admin processes

\n\n

Run admin/management tasks as one-off processes

\n
\n
\n\n\n \n\n\n" + want := "\n\n\n \n\n The Twelve-Factor App \n \n \n\n \n \n\n \n \n\n \n \n\n\n \n\n
\n

The Twelve-Factor App

\n
\n\n
\n
\n

Introduction

\n\n

In the modern era, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps that:

\n\n
    \n
  • Use declarative formats for setup automation, to minimize time and cost for new developers joining the project;
  • \n\n
  • Have a clean contract with the underlying operating system, offering maximum portability between execution environments;
  • \n\n
  • Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration;
  • \n\n
  • Minimize divergence between development and production, enabling continuous deployment for maximum agility;
  • \n\n
  • And can scale up without significant changes to tooling, architecture, or development practices.
  • \n
\n\n

The twelve-factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).

\n
\n
\n

Background

\n\n

The contributors to this document have been directly involved in the development and deployment of hundreds of apps, and indirectly witnessed the development, operation, and scaling of hundreds of thousands of apps via our work on the Heroku platform.

\n\n

This document synthesizes all of our experience and observations on a wide variety of software-as-a-service apps in the wild. It is a triangulation on ideal practices for app development, paying particular attention to the dynamics of the organic growth of an app over time, the dynamics of collaboration between developers working on the app’s codebase, and avoiding the cost of software erosion.

\n\n

Our motivation is to raise awareness of some systemic problems we’ve seen in modern application development, to provide a shared vocabulary for discussing those problems, and to offer a set of broad conceptual solutions to those problems with accompanying terminology. The format is inspired by Martin Fowler’s books Patterns of Enterprise Application Architecture and Refactoring.

\n
\n
\n

Who should read this document?

\n\n

Any developer building applications which run as a service. Ops engineers who deploy or manage such applications.

\n
\n
\n\n
\n
\n

The Twelve Factors

\n\n

I. Codebase

\n\n

One codebase tracked in revision control, many deploys

\n\n

II. Dependencies

\n\n

Explicitly declare and isolate dependencies

\n\n

III. Config

\n\n

Store config in the environment

\n\n

IV. Backing services

\n\n

Treat backing services as attached resources

\n\n

V. Build, release, run

\n\n

Strictly separate build and run stages

\n\n

VI. Processes

\n\n

Execute the app as one or more stateless processes

\n\n

VII. Port binding

\n\n

Export services via port binding

\n\n

VIII. Concurrency

\n\n

Scale out via the process model

\n\n

IX. Disposability

\n\n

Maximize robustness with fast startup and graceful shutdown

\n\n

X. Dev/prod parity

\n\n

Keep development, staging, and production as similar as possible

\n\n

XI. Logs

\n\n

Treat logs as event streams

\n\n

XII. Admin processes

\n\n

Run admin/management tasks as one-off processes

\n
\n
\n\n\n \n\n\n" if got != want { t.Errorf("got %v, wanted %v", got, want) diff --git a/cmd/get.go b/cmd/get.go index b2a2693..dd92a2a 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "errors" "fmt" "io/ioutil" @@ -41,7 +42,7 @@ func init() { 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.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().BoolVarP(&getOpts.stdout, "stdout", "", false, "print to standard output") getCmd.Flags().BoolVarP(&getOpts.images, "images", "", false, "retrieve images only") @@ -73,6 +74,7 @@ var getCmd = &cobra.Command{ // check provided format is in list formatEnum := map[string]bool{ "md": true, + "json": true, "html": true, "epub": 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" { filename := book.ToHtml(c, getOpts.output) diff --git a/cmd/version.go b/cmd/version.go index 539ae14..b991be8 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of papeer", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("papeer v0.7.1") + fmt.Println("papeer v0.8.0") }, }