Skip to content

Commit

Permalink
Refactor run function to remove unused title and cover logging, and r…
Browse files Browse the repository at this point in the history
…eplace metadata extraction with front matter parsing.
  • Loading branch information
harrymaynard committed Feb 2, 2025
1 parent 84c86e5 commit 6541b18
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
19 changes: 1 addition & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158621,7 +158621,6 @@ var matter = /*@__PURE__*/getDefaultExportFromCjs(grayMatterExports);

// eslint-disable-next-line @typescript-eslint/require-await
const run = async (inputs) => {
coreExports.info(`title is: ${inputs.title}`);
// GitHub workspace directory.
const gitHubWorkspaceDir = process.env.GITHUB_WORKSPACE; // || '/github/workspace'
// Inputs.
Expand Down Expand Up @@ -158655,7 +158654,6 @@ const run = async (inputs) => {
const buffer = require$$0$6.readFileSync(coverFilePath);
coverFile = new File([buffer], fileName);
}
coreExports.info(`cover is: ${cover}`);
const includes = markdownFiles?.split('\n') || [];
const chapters = [];
for (const includeIndex in includes) {
Expand All @@ -158669,22 +158667,7 @@ const run = async (inputs) => {
const markdownFileName = markdownFileNames[fileIndex];
// Read the markdown file to get the content of the file.
const markdown = require$$0$6.readFileSync(require$$1$6.resolve(import.meta.dirname, markdownFileName)).toString().trim();
// Extract chapter title from markdown metadata.
const chapterTitleMatch = markdown.match(/\[metadata:title\]:- "([^"]+)"/i);
chapterTitleMatch ? chapterTitleMatch[1].trim() : undefined;
// Extract chapter author from markdown metadata.
const chapterAuthorMatch = markdown.match(/\[metadata:author\]:- "([^"]+)"/i);
chapterAuthorMatch ? chapterAuthorMatch[1].trim() : undefined;
// Extract chapter excludeFromToc from markdown metadata.
const chapterExcludeFromTocMatch = markdown.match(/\[metadata:excludeFromToc\]:- "([^"]+)"/i);
chapterExcludeFromTocMatch
? chapterExcludeFromTocMatch[1].trim() === 'true'
: undefined;
// Extract chapter excludeFromToc from markdown metadata.
const chapterBeforeTocMatch = markdown.match(/\[metadata:beforeToc\]:- "([^"]+)"/i);
chapterBeforeTocMatch
? chapterBeforeTocMatch[1].trim() === 'true'
: undefined;
// Parse the front matter from the markdown content.
const frontMatterResult = matter(markdown);
// Generate the HTML content from markdown.
const html = await marked.parse(frontMatterResult.content);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 1 addition & 23 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ interface IInputs {

// eslint-disable-next-line @typescript-eslint/require-await
export const run = async (inputs: IInputs): Promise<void> => {
core.info(`title is: ${inputs.title}`)

// GitHub workspace directory.
const gitHubWorkspaceDir: string = process.env.GITHUB_WORKSPACE // || '/github/workspace'

Expand Down Expand Up @@ -65,7 +63,6 @@ export const run = async (inputs: IInputs): Promise<void> => {

coverFile = new File([buffer], fileName)
}
core.info(`cover is: ${cover}`)

const includes: Array<string> = markdownFiles?.split('\n') || []
const chapters: Array<IChapter> = []
Expand All @@ -85,26 +82,7 @@ export const run = async (inputs: IInputs): Promise<void> => {
// Read the markdown file to get the content of the file.
const markdown: string = fs.readFileSync(path.resolve(import.meta.dirname, markdownFileName)).toString().trim()

// Extract chapter title from markdown metadata.
const chapterTitleMatch: Array<string> = markdown.match(/\[metadata:title\]:- "([^"]+)"/i)
const chapterTitle: string | undefined = chapterTitleMatch ? chapterTitleMatch[1].trim() : undefined

// Extract chapter author from markdown metadata.
const chapterAuthorMatch: Array<string> = markdown.match(/\[metadata:author\]:- "([^"]+)"/i)
const chapterAuthor: string | undefined = chapterAuthorMatch ? chapterAuthorMatch[1].trim() : undefined

// Extract chapter excludeFromToc from markdown metadata.
const chapterExcludeFromTocMatch: Array<string> = markdown.match(/\[metadata:excludeFromToc\]:- "([^"]+)"/i)
const chapterExcludeFromToc: boolean | undefined = chapterExcludeFromTocMatch
? chapterExcludeFromTocMatch[1].trim() === 'true'
: undefined

// Extract chapter excludeFromToc from markdown metadata.
const chapterBeforeTocMatch: Array<string> = markdown.match(/\[metadata:beforeToc\]:- "([^"]+)"/i)
const chapterBeforeToc: boolean | undefined = chapterBeforeTocMatch
? chapterBeforeTocMatch[1].trim() === 'true'
: undefined

// Parse the front matter from the markdown content.
const frontMatterResult = matter(markdown)

// Generate the HTML content from markdown.
Expand Down

0 comments on commit 6541b18

Please sign in to comment.