Skip to content

Commit

Permalink
Added dependency epub-gen and initial usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
harrymaynard committed Aug 16, 2024
1 parent a563223 commit 7a67c38
Show file tree
Hide file tree
Showing 5 changed files with 1,228 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: book
path: example.html
path: book.epub
38 changes: 33 additions & 5 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,51 @@ import path from 'path'
import { fileURLToPath } from 'url'
import { marked } from 'marked'
import { glob } from 'glob'
import EPub from 'epub-gen'

const include = process.env.INPUT_INCLUDE
const includes = include.split('\\n')
if (!include) {
console.error('Missing required input: \'include\'')
process.exit(1)
}

const includes = include?.split('\\n') || []
let allMarkdown = ''

console.log('include:', include)

for (const i in includes) {
const regex = includes[i]
for (const includeIndex in includes) {
const regex = includes[includeIndex]
const markdownFileNames = await glob(regex.trim(), { ignore: 'node_modules/**' })
console.log('markdownFileNames:', markdownFileNames)
for (const j in markdownFileNames) {
const markdownFileName = markdownFileNames[j]
for (const fileIndex in markdownFileNames) {
const markdownFileName = markdownFileNames[fileIndex]
const markdown = fs.readFileSync(path.resolve(import.meta.dirname, markdownFileName)).toString().trim()
allMarkdown += `${markdown}\n\n`
}
}


const option = {
title: "Alice's Adventures in Wonderland", // *Required, title of the book.
author: "Lewis Carroll", // *Required, name of the author.
publisher: "Macmillan & Co.", // optional
cover: "http://demo.com/url-to-cover-image.jpg", // Url or File path, both ok.
content: [
{
title: "About the author", // Optional
author: "John Doe", // Optional
data: "<h2>Charles Lutwidge Dodgson</h2>"
+"<div lang=\"en\">Better known by the pen name Lewis Carroll...</div>" // pass html string
},
{
title: "Down the Rabbit Hole",
data: "<p>Alice was beginning to get very tired...</p>"
},
]
}

await new EPub(option, '/book.epub').promise
//console.log('allMarkdown:', allMarkdown)
const html = marked.parse(allMarkdown)
console.log('html:', html, '\n')
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

node /action.js " '%s'" "$@"
node /action.js

# `$#` expands to the number of arguments and `$@` expands to the supplied `args`
printf '%d args:' "$#"
Expand Down
Loading

0 comments on commit 7a67c38

Please sign in to comment.