Skip to content

Commit

Permalink
Refactor summary processing
Browse files Browse the repository at this point in the history
Co-authored-by: Kaspar Emanuel <[email protected]>
  • Loading branch information
kasbah and kasbah committed Nov 1, 2022
1 parent b8226f5 commit 60d7549
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions e2e/cypress/integration/readme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Readme style', () => {
})
})

it('should render :emoji: in readme and project description', () => {
it('renders :emoji: in readme and project description', () => {
const username = getFakeUsername()
const email = faker.unique(faker.internet.email)
const password = '123456'
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Readme style', () => {
cy.get('[data-cy=readme]').should('contain.text', '🤓')
})

it('should not modify the urls for GitHub Actions badges', () => {
it('preserves URLs for GitHub Actions badges', () => {
const username = getFakeUsername()
const email = faker.unique(faker.internet.email)
const password = '123456'
Expand Down
50 changes: 25 additions & 25 deletions processor/src/tasks/writeKitspaceYaml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'node:path'

import { unified } from 'unified'
import rehypeHighlight from 'rehype-highlight'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import remarkEmoji from 'remark-emoji'
Expand All @@ -12,46 +11,47 @@ import remarkRehype from 'remark-rehype'
import { JobData } from '../jobData.js'
import * as utils from '../utils.js'


export default async function writeKitspaceYaml(
job,
{ kitspaceYaml, outputDir }: Partial<JobData>,
) {
const kitspaceYamlJson = path.join(outputDir, 'kitspace-yaml.json')
job.updateProgress({ status: 'in_progress', file: kitspaceYamlJson })
const KitspaceYamlJsonLinkified = await linkifyKitspaceYaml(kitspaceYaml)

const rendered = await renderKitspaceYamlSummaries(kitspaceYaml)

return utils
.writeFile(kitspaceYamlJson, JSON.stringify(KitspaceYamlJsonLinkified, null, 2))
.writeFile(kitspaceYamlJson, JSON.stringify(rendered, null, 2))
.then(() => job.updateProgress({ status: 'done', file: kitspaceYamlJson }))
.catch(error =>
job.updateProgress({ status: 'failed', file: kitspaceYamlJson, error }),
)
}

async function linkifyKitspaceYaml(kitspaceYaml) {
async function renderKitspaceYamlSummaries(kitspaceYaml) {
if (kitspaceYaml.multi) {
const linkifiedKitspaceYaml = kitspaceYaml
Object.keys(kitspaceYaml.multi).forEach(async subProject => {
linkifiedKitspaceYaml.multi[subProject] = await renderProjectSummary(kitspaceYaml.multi[subProject])
})
return linkifiedKitspaceYaml
const rendered = { multi: {} }
for (const key of Object.keys(kitspaceYaml.multi)) {
const subProject = kitspaceYaml.multi[key]
rendered.multi[key] = {
...subProject,
summary: await renderSummary(subProject.summary),
}
}
return rendered
}
return renderProjectSummary(kitspaceYaml)
return { ...kitspaceYaml, summary: await renderSummary(kitspaceYaml.summary) }
}

async function renderProjectSummary(kitspaceYaml) {
const summary = kitspaceYaml.summary || ''
const Remarker = unified()
.use(remarkParse)
.use(remarkEmoji)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeHighlight)
.use(rehypeSanitize)
.use(rehypeStringify)

const processedMarkdown = await Remarker.process(summary)
kitspaceYaml.summary = String(processedMarkdown)
return kitspaceYaml
const Remarker = unified()
.use(remarkParse)
.use(remarkEmoji)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeSanitize)
.use(rehypeStringify)

async function renderSummary(summary = ''): Promise<string> {
const rendered = await Remarker.process(summary)
return String(rendered)
}
2 changes: 1 addition & 1 deletion processor/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function toGitHubRawUrl(url: string) {
if (parsedUrl.hostname === 'github.com') {
parsedUrl.hostname = 'raw.githubusercontent.com'
const urlPath = parsedUrl.pathname.split('/')
// Avoid using modifying github actions status badges.
// Avoid modifying github actions status badges.
const isWorkflowPath = ['workflows', 'actions'].includes(urlPath?.[3])

if (!isWorkflowPath) {
Expand Down

0 comments on commit 60d7549

Please sign in to comment.