Skip to content
Closed
10 changes: 1 addition & 9 deletions src/article-api/lib/graphql-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Context, Page } from '@/types'
import { renderContent } from '@/content-render/index'
import matter from '@gr2m/gray-matter'

/**
* Extract manual content from page markdown
Expand All @@ -15,14 +14,7 @@ export async function extractManualContent(page: Page, context: Context): Promis

if (markerIndex <= 0) return ''

const { content } = matter(page.markdown)
const manualContentMarkerIndex = content.indexOf(
'<!-- Content after this section is automatically generated -->',
)

if (manualContentMarkerIndex <= 0) return ''

const rawManualContent = content.substring(0, manualContentMarkerIndex).trim()
const rawManualContent = page.markdown.substring(0, markerIndex).trim()
if (!rawManualContent) return ''

return await renderContent(rawManualContent, {
Expand Down
19 changes: 6 additions & 13 deletions src/article-api/transformers/audit-logs-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { PageTransformer } from './types'
import type { CategorizedEvents } from '@/audit-logs/types'
import { renderContent } from '@/content-render/index'
import { loadTemplate } from '@/article-api/lib/load-template'
import matter from '@gr2m/gray-matter'

/**
* Transformer for Audit Logs pages
Expand Down Expand Up @@ -46,18 +45,12 @@ export class AuditLogsTransformer implements PageTransformer {
'<!-- Content after this section is automatically generated -->',
)
if (markerIndex > 0) {
const { content } = matter(page.markdown)
const manualContentMarkerIndex = content.indexOf(
'<!-- Content after this section is automatically generated -->',
)
if (manualContentMarkerIndex > 0) {
const rawManualContent = content.substring(0, manualContentMarkerIndex).trim()
if (rawManualContent) {
manualContent = await renderContent(rawManualContent, {
...context,
markdownRequested: true,
})
}
const rawManualContent = page.markdown.substring(0, markerIndex).trim()
if (rawManualContent) {
manualContent = await renderContent(rawManualContent, {
...context,
markdownRequested: true,
})
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/article-api/transformers/github-apps-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Context, Page } from '@/types'
import type { PageTransformer } from './types'
import { renderContent } from '@/content-render/index'
import { loadTemplate } from '@/article-api/lib/load-template'
import matter from '@gr2m/gray-matter'

const DEBUG = process.env.RUNNER_DEBUG === '1' || process.env.DEBUG === '1'

Expand Down Expand Up @@ -131,7 +130,7 @@ export class GithubAppsTransformer implements PageTransformer {
// Prepare manual content
let manualContent = ''
if (page.markdown) {
const { content } = matter(page.markdown)
const content = page.markdown
// GitHub Apps pages don't have the automated marker, so we render all markdown content
if (content.trim()) {
manualContent = await renderContent(content, {
Expand Down
19 changes: 6 additions & 13 deletions src/article-api/transformers/rest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { engine } from '@/content-render/liquid/engine'
import { apiTransformerTags } from '@/article-api/liquid-renderers'
import { loadTemplate } from '@/article-api/lib/load-template'
import { summarizeSchema } from '@/article-api/lib/summarize-schema'
import matter from '@gr2m/gray-matter'
import { fastTextOnly } from '@/content-render/unified/text-only'
import GithubSlugger from 'github-slugger'

Expand Down Expand Up @@ -86,18 +85,12 @@ export class RestTransformer implements PageTransformer {
'<!-- Content after this section is automatically generated -->',
)
if (markerIndex > 0) {
const { content } = matter(page.markdown)
const manualContentMarkerIndex = content.indexOf(
'<!-- Content after this section is automatically generated -->',
)
if (manualContentMarkerIndex > 0) {
const rawManualContent = content.substring(0, manualContentMarkerIndex).trim()
if (rawManualContent) {
manualContent = await renderContent(rawManualContent, {
...context,
markdownRequested: true,
})
}
const rawManualContent = page.markdown.substring(0, markerIndex).trim()
if (rawManualContent) {
manualContent = await renderContent(rawManualContent, {
...context,
markdownRequested: true,
})
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/article-api/transformers/webhooks-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { PageTransformer } from './types'
import { renderContent } from '@/content-render/index'
import { fastTextOnly } from '@/content-render/unified/text-only'
import { loadTemplate } from '@/article-api/lib/load-template'
import matter from '@gr2m/gray-matter'

/**
* Transformer for Webhooks pages.
Expand Down Expand Up @@ -32,7 +31,7 @@ export class WebhooksTransformer implements PageTransformer {
// Prepare manual content
let manualContent = ''
if (page.markdown) {
const { content } = matter(page.markdown)
const content = page.markdown
const markerIndex = content.indexOf(
'<!-- Content after this section is automatically generated -->',
)
Expand Down
8 changes: 4 additions & 4 deletions src/content-linter/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addError, filterTokens } from 'markdownlint-rule-helpers'
import matter from '@gr2m/gray-matter'

import type { RuleParams, RuleErrorCallback, MarkdownToken } from '@/content-linter/types'
import { parseYamlFrontmatter } from '@/frame/lib/parse-yaml-frontmatter'

// Adds an error object with details conditionally via the onError callback
export function addFixErrorDetail(
Expand Down Expand Up @@ -147,10 +147,10 @@ export const docsDomains = ['docs.github.com', 'help.github.com', 'developer.git
// Returns frontmatter as a Record with unknown values since YAML can contain various types
export function getFrontmatter(lines: string[]): Record<string, unknown> | null {
const fmString = lines.join('\n')
const { data } = matter(fmString)
const { data } = parseYamlFrontmatter(fmString)
// If there is no frontmatter or the frontmatter contains
// no keys, matter will return an empty object.
if (Object.keys(data).length === 0) return null
// no keys, the parser will return an empty object.
if (data == null || Object.keys(data).length === 0) return null
return data
}

Expand Down
Loading
Loading