1
0
mirror of synced 2026-01-07 00:01:39 -05:00

Merge pull request #33702 from github/repo-sync

Repo sync
This commit is contained in:
docs-bot
2024-06-25 10:57:08 -07:00
committed by GitHub
5 changed files with 61 additions and 25 deletions

View File

@@ -1,3 +1,7 @@
import type { Response, NextFunction } from 'express'
import type { ExtendedRequest } from '@/types'
// This middleware rewrites the URL of requests that contain the
// portion of `/cb-\d+/`.
// "cb" stands for "cache bust".
@@ -10,7 +14,11 @@
const regex = /\/cb-\d+\//
export default function assetPreprocessing(req, res, next) {
export default function assetPreprocessing(
req: ExtendedRequest,
res: Response,
next: NextFunction,
) {
if (req.path.startsWith('/assets/')) {
// We didn't use to have a rule about all image assets must be
// lower case. So we've exposed things like:

View File

@@ -48,11 +48,11 @@ import renderProductName from './context/render-product-name'
import features from '@/versions/middleware/features.js'
import productExamples from './context/product-examples'
import productGroups from './context/product-groups'
import featuredLinks from '@/landings/middleware/featured-links.js'
import featuredLinks from '@/landings/middleware/featured-links'
import learningTrack from '@/learning-track/middleware/learning-track.js'
import next from './next.js'
import renderPage from './render-page.js'
import assetPreprocessing from '@/assets/middleware/asset-preprocessing.js'
import assetPreprocessing from '@/assets/middleware/asset-preprocessing'
import archivedAssetRedirects from '@/archives/middleware/archived-asset-redirects.js'
import favicons from './favicons.js'
import setStaticAssetCaching from '@/assets/middleware/static-asset-caching.js'

View File

@@ -1,5 +1,8 @@
import getLinkData from '#src/learning-track/lib/get-link-data.js'
import { renderContent } from '#src/content-render/index.js'
import type { Response, NextFunction } from 'express'
import type { ExtendedRequest, FeaturedLinkExpanded } from '@/types'
import getLinkData from '@/learning-track/lib/get-link-data.js'
import { renderContent } from '@/content-render/index.js'
/**
* This is the max. number of featured links, by any category, that we
@@ -24,7 +27,12 @@ import { renderContent } from '#src/content-render/index.js'
const MAX_FEATURED_LINKS = 4
// this middleware adds properties to the context object
export default async function featuredLinks(req, res, next) {
export default async function featuredLinks(
req: ExtendedRequest,
res: Response,
next: NextFunction,
) {
if (!req.context) throw new Error('request is not contextualized')
if (!req.context.page) return next()
if (
@@ -46,7 +54,9 @@ export default async function featuredLinks(req, res, next) {
// the provided string title or an empty title. When the title is empty,
// it indicates the video is not versioned for the current version
req.context.featuredLinks[key] = []
for (const featuredLink of req.context.page.featuredLinks[key]) {
if (!(key in req.context.page.featuredLinks))
throw new Error('featureLinks key not found in Page')
for (const featuredLink of req.context.page.featuredLinks[key]!) {
const title = await renderContent(featuredLink.title, req.context, {
textOnly: true,
})
@@ -60,12 +70,15 @@ export default async function featuredLinks(req, res, next) {
}
}
} else {
req.context.featuredLinks[key] = await getLinkData(
req.context.page.featuredLinks[key],
if (!(key in req.context.page.featuredLinks))
throw new Error('featureLinks key not found in Page')
const pageFeaturedLink = req.context.page.featuredLinks[key]
req.context.featuredLinks[key] = (await getLinkData(
pageFeaturedLink,
req.context,
{ title: true, intro: true, fullTitle: true },
MAX_FEATURED_LINKS,
)
)) as FeaturedLinkExpanded[] // Remove ones `getLinkData` is TS
}
}

View File

@@ -1,7 +1,7 @@
import { describe, expect, test, vi } from 'vitest'
import { getDOM } from '#src/tests/helpers/e2etest.js'
import enterpriseServerReleases from '#src/versions/lib/enterprise-server-releases.js'
import { getDOM } from '@/tests/helpers/e2etest.js'
import enterpriseServerReleases from '@/versions/lib/enterprise-server-releases.js'
describe('featuredLinks', () => {
vi.setConfig({ testTimeout: 60 * 1000 })

View File

@@ -36,19 +36,7 @@ export type PageFrontmatter = {
authors?: string[]
examples_source?: string
effectiveDate?: string
featuredLinks?: {
gettingStarted?: string[]
startHere?: string[]
guideCards?: string[]
popular?: string[]
popularHeading?: string
videos?: {
title: string
href: string
}[]
videoHeadings?: string
}[]
featuredLinks?: FeaturedLinks
changelog?: ChangeLog
type?: string
topics?: string[]
@@ -67,6 +55,19 @@ export type PageFrontmatter = {
childGroups?: ChildGroup[]
}
type FeaturedLinks = {
gettingStarted?: string[]
startHere?: string[]
guideCards?: string[]
popular?: string[]
popularHeading?: string
videos?: {
title: string
href: string
}[]
videoHeadings?: string
}
export type ChildGroup = {
name: string
octicon: string
@@ -157,6 +158,19 @@ export type Context = {
productCommunityExamples?: ProductExample[]
productUserExamples?: ProductExample[]
productGroups?: ProductGroup[]
featuredLinks?: FeaturedLinksExpanded
}
export type FeaturedLinkExpanded = {
href: string
title: string
page?: Page
fullTitle?: string
intro?: string
}
type FeaturedLinksExpanded = {
[key: string]: FeaturedLinkExpanded[]
}
export type ProductGroup = {
@@ -296,6 +310,7 @@ export type Page = {
layout?: string | boolean
earlyAccessToc?: boolean
autogenerated?: string
featuredLinks?: FeaturedLinksExpanded
}
type ChangeLog = {