Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo sync #36169

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/kubernetes/production/deployments/webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ spec:
image: docs-internal
resources:
requests:
cpu: 8000m
memory: 10Gi
cpu: 4000m
memory: 8Gi
limits:
cpu: 16000m
memory: 14Gi
cpu: 8000m
memory: 16Gi
ports:
- name: http
containerPort: 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ To ensure your cost centers reflect spending as intended, it's important to unde

### Cost center allocation for {% data variables.product.prodname_GH_advanced_security %}

* If a user belongs to a cost center, all charges associated with the user is billed to the cost center.
* If a user belongs to a cost center, all charges associated with the user are billed to the cost center.
* If a user does not belong to any cost center, usage is charged to the enterprise's default payment method and grouped under "Enterprise Only" spending on the usage page.

### Cost center allocation for {% data variables.product.prodname_enterprise %}
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.0",
"remark-remove-comments": "^1.0.1",
"remark-stringify": "^11.0.0",
"rss-parser": "^3.13.0",
"scroll-anchoring": "^0.1.0",
"semver": "^7.6.2",
Expand Down
8 changes: 7 additions & 1 deletion src/content-render/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderLiquid } from './liquid/index.js'
import { renderUnified } from './unified/index.js'
import { renderMarkdown, renderUnified } from './unified/index.js'
import { engine } from './liquid/engine.js'

const globalCache = new Map()
Expand All @@ -26,6 +26,12 @@ export async function renderContent(template = '', context = {}, options = {}) {
}
try {
template = await renderLiquid(template, context)
if (context.markdownRequested) {
const md = await renderMarkdown(template, context, options)

return md
}

const html = await renderUnified(template, context, options)
if (cacheKey) {
globalCache.set(cacheKey, html)
Expand Down
10 changes: 9 additions & 1 deletion src/content-render/unified/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fastTextOnly } from './text-only.js'
import { createProcessor } from './processor.js'
import { createProcessor, createMarkdownOnlyProcessor } from './processor.js'

export async function renderUnified(template, context, options) {
const processor = createProcessor(context)
Expand All @@ -12,3 +12,11 @@ export async function renderUnified(template, context, options) {

return html.trim()
}

export async function renderMarkdown(template, context, options) {
const processor = createMarkdownOnlyProcessor(context)
const vFile = await processor.process(template)
let markdown = vFile.toString()

return markdown.trim()
}
5 changes: 5 additions & 0 deletions src/content-render/unified/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import annotate from './annotate.js'
import alerts from './alerts.js'
import replaceDomain from './replace-domain.js'
import removeHtmlComments from 'remark-remove-comments'
import remarkStringify from 'remark-stringify'

export function createProcessor(context) {
return (
Expand Down Expand Up @@ -79,6 +80,10 @@ export function createProcessor(context) {
)
}

export function createMarkdownOnlyProcessor(context) {
return unified().use(remarkParse).use(gfm).use(remarkStringify)
}

export function createMinimalProcessor(context) {
return unified()
.use(remarkParse)
Expand Down
2 changes: 1 addition & 1 deletion src/fixtures/tests/permissions-callout.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('permission statements', () => {
})

test('page with permission frontmatter and product statement', async () => {
const $ = await getDOM('/get-started/foo/page-with-permissions-and-product-callout.md')
const $ = await getDOM('/get-started/foo/page-with-permissions-and-product-callout')
const html = $('[data-testid=permissions-callout] div').html()
// part of the UI
expect(html).toMatch('Who can use this feature')
Expand Down
8 changes: 8 additions & 0 deletions src/frame/middleware/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export default async function contextualize(

req.context.process = { env: {} }

if (req.pagePath && req.pagePath.endsWith('.md')) {
req.context.markdownRequested = true

// req.pagePath is used later in the rendering pipeline to
// locate the file in the tree so it cannot have .md
req.pagePath = req.pagePath.replace(/\/index\.md$/, '').replace(/\.md$/, '')
}

// define each context property explicitly for code-search friendliness
// e.g. searches for "req.context.page" will include results from this file
req.context.currentLanguage = req.language
Expand Down
9 changes: 9 additions & 0 deletions src/frame/middleware/render-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ export default async function renderPage(req: ExtendedRequest, res: Response) {
}
}

if (context.markdownRequested) {
if (!page.autogenerated && page.documentType === 'article') {
return res.type('text/markdown').send(req.context.renderedPage)
} else {
const newUrl = req.originalUrl.replace(req.path, req.path.replace(/\.md$/, ''))
return res.redirect(newUrl)
}
}

defaultCacheControl(res)

return nextHandleRequest(req, res)
Expand Down
7 changes: 2 additions & 5 deletions src/shielding/middleware/handle-invalid-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ export default function handleInvalidPaths(
return res.status(404).send('Not found')
}

if (req.path.endsWith('/index.md') || req.path.endsWith('.md')) {
if (req.path.endsWith('/index.md')) {
defaultCacheControl(res)
// The originalUrl is the full URL including query string.
// E.g. `/en/foo.md?bar=baz`
const newUrl = req.originalUrl.replace(
req.path,
req.path.replace(/\/index\.md$/, '').replace(/\.md$/, ''),
)
const newUrl = req.originalUrl.replace(req.path, req.path.replace(/\/index\.md$/, ''))
return res.redirect(newUrl)
}

Expand Down
3 changes: 2 additions & 1 deletion src/shielding/tests/shielding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ describe('index.md and .md suffixes', () => {
}
})

test('any URL that ends with /.md redirects', async () => {
// TODO-ARTICLEAPI: unskip tests or replace when ready to ship article API
test.skip('any URL that ends with /.md redirects', async () => {
// With language prefix
{
const res = await get('/en/get-started/hello.md')
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export type Context = {
currentLearningTrack?: LearningTrack | null
renderedPage?: string
miniTocItems?: string | undefined
markdownRequested?: boolean
}
export type LearningTracks = {
[group: string]: {
Expand Down
Loading