Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7ac983

Browse files
authoredAug 25, 2021
allow use of full titles on landing page (github#20327)
1 parent e9ce3cd commit c7ac983

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed
 

‎components/context/ProductLandingContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type FeaturedLink = {
1717
authors?: Array<string>
1818
hideIntro?: boolean
1919
date?: string
20+
fullTitle?: string
2021
}
2122
export type CodeExample = {
2223
title: string
@@ -88,6 +89,7 @@ export const getFeaturedLinksFromReq = (req: any): Record<string, Array<Featured
8889
title: entry.title,
8990
intro: entry.intro,
9091
authors: entry.page.authors || [],
92+
fullTitle: entry.fullTitle,
9193
})),
9294
]
9395
})
@@ -158,6 +160,7 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
158160
title: link.title,
159161
intro: link.intro,
160162
authors: link.page.authors || [],
163+
fullTitle: link.fullTitle,
161164
}
162165
}),
163166
}

‎components/landing/ArticleList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ export const ArticleList = ({
5252
className="py-3"
5353
title={
5454
<h4 data-testid="link-with-intro-title">
55-
<span dangerouslySetInnerHTML={{ __html: link.title }} />
55+
<span
56+
dangerouslySetInnerHTML={
57+
link.fullTitle ? { __html: link.fullTitle } : { __html: link.title }
58+
}
59+
/>
5660
</h4>
5761
}
5862
>

‎lib/get-link-data.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import renderContent from './render-content/index.js'
66

77
// rawLinks is an array of paths: [ '/foo' ]
88
// we need to convert it to an array of localized objects: [ { href: '/en/foo', title: 'Foo', intro: 'Description here' } ]
9-
export default async (rawLinks, context, option = { title: true, intro: true }) => {
9+
export default async (
10+
rawLinks,
11+
context,
12+
option = { title: true, intro: true, fullTitle: false }
13+
) => {
1014
if (!rawLinks) return
1115

1216
if (typeof rawLinks === 'string') {
@@ -46,6 +50,11 @@ const processLink = async (link, context, option) => {
4650
result.title = await linkedPage.renderTitle(context, opts)
4751
}
4852

53+
if (option.fullTitle) {
54+
opts.preferShort = false
55+
result.fullTitle = await linkedPage.renderTitle(context, opts)
56+
}
57+
4958
if (option.intro) {
5059
result.intro = await linkedPage.renderProp('intro', context, opts)
5160
}

‎lib/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ class Page {
154154
return productMap[this.parentProductId]
155155
}
156156

157-
async renderTitle(context, opts = {}) {
158-
return this.shortTitle
157+
async renderTitle(context, opts = { preferShort: true }) {
158+
return opts.preferShort && this.shortTitle
159159
? this.renderProp('shortTitle', context, opts)
160160
: this.renderProp('title', context, opts)
161161
}

‎middleware/featured-links.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default async function featuredLinks(req, res, next) {
1818
for (const key in req.context.page.featuredLinks) {
1919
req.context.featuredLinks[key] = await getLinkData(
2020
req.context.page.featuredLinks[key],
21-
req.context
21+
req.context,
22+
{ title: true, intro: true, fullTitle: true }
2223
)
2324
}
2425

0 commit comments

Comments
 (0)
Please sign in to comment.