Skip to content

Commit

Permalink
feat: new theme option
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-solanki committed Aug 3, 2022
1 parent a0f7f10 commit 1ffa7d5
Show file tree
Hide file tree
Showing 7 changed files with 6,062 additions and 2,257 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ Converts markdown files to HTML
Check action.yml for docs.

Detailed readme coming soon.

## Credits

- THanks [sindresorhus](https://github.com/sindresorhus/github-markdown-css) for markdown styles
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
files:
description: 'Stringified Array of [Array of source md file & file to generate] (i.e. [ ["index.md", "index.html"], ["changelog.md", "changelog.html"]])'
required: false
theme:
description: 'Github Markdown theme to use. Options: "Auto", "Light" or "Dark"'
default: Auto
debug:
description: Boolean value which will tell action to log the action it performs. Useful for debugging.
default: false
Expand Down
6,408 changes: 4,157 additions & 2,251 deletions dist/index.js

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable no-nested-ternary */
// Docs: https://docs.github.com/en/actions
const core = require('@actions/core')
const { promises: fs } = require('fs')
const MarkdownIt = require('./markdown-it.min')
const stylesheetContent = require('./gh-md-style')
const themeAuto = require('./styles/github-markdown')
const themeLight = require('./styles/github-markdown-light')
const themeDark = require('./styles/github-markdown-dark')

const md = new MarkdownIt()

async function mdToHtml(filePath, debug) {
async function mdToHtml(filePath, debug, theme) {
// Read source file
const content = await fs.readFile(filePath, 'utf8')
if (debug) core.info(`content of ${filePath}: ${content}`)
Expand All @@ -20,7 +23,11 @@ async function mdToHtml(filePath, debug) {
<meta charset="UTF-8" />
<title>Changelog</title>
<style>
${stylesheetContent}
${theme === 'light'
? themeLight
: theme === 'dark'
? themeDark
: themeAuto}
/* recommended style from docs: https://github.com/sindresorhus/github-markdown-css */
.markdown-body {
box-sizing: border-box;
Expand Down Expand Up @@ -49,8 +56,12 @@ ${rendered}
try {
// 👉 Get config
const debug = Boolean(JSON.parse(core.getInput('debug')))
const theme = core.getInput('theme')

if (debug) core.info(`debug: ${debug}`)

if (debug) core.info(`theme: ${theme}`)

const files = JSON.parse(core.getInput('files'))
if (debug) core.info(`files: ${files}`)

Expand All @@ -71,8 +82,8 @@ ${rendered}
if (debug) core.info(`Working on: ${JSON.stringify(files[index])}`)
if (debug) core.info(`writing ${files[index][1]}`)

if (debug) core.info(`HTML content to write: ${await mdToHtml(files[index][0], debug)}`)
await fs.writeFile(files[index][1], await mdToHtml(files[index][0], debug), err => { if (err) core.warning(err) })
if (debug) core.info(`HTML content to write: ${await mdToHtml(files[index][0], debug, theme)}`)
await fs.writeFile(files[index][1], await mdToHtml(files[index][0], debug, theme), err => { if (err) core.warning(err) })
if (debug) core.info('Written to HTML file')
}

Expand Down
Loading

0 comments on commit 1ffa7d5

Please sign in to comment.