From a6ba42f3e19990ebb0e51f35216a44c34a88885a Mon Sep 17 00:00:00 2001 From: lapwat Date: Mon, 24 Apr 2023 19:10:31 +0200 Subject: [PATCH] add table of content to ebooks --- book/format.go | 16 ++++++++++++++++ book/scraper_test.go | 2 +- cmd/version.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/book/format.go b/book/format.go index dff1a43..c8f1312 100644 --- a/book/format.go +++ b/book/format.go @@ -127,6 +127,22 @@ func ToEpub(c chapter, filename string) string { func AppendToEpub(e *epub.Epub, c chapter) { content := "" + // append table of content + if len(c.SubChapters()) > 1 { + html := "

Table of Contents

" + + html += "
    " + for _, sc := range c.SubChapters() { + html += fmt.Sprintf("
  1. %s
  2. ", sc.Name()) + } + html += "
" + + _, err := e.AddSection(html, "Table of Contents", "", "") + if err != nil { + log.Fatal(err) + } + } + // chapter content if c.config.Include { diff --git a/book/scraper_test.go b/book/scraper_test.go index ce7963f..911c17e 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/version.go b/cmd/version.go index 15822a3..539ae14 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.0") + fmt.Println("papeer v0.7.1") }, }