Skip to content

Commit 2c0051b

Browse files
authored
Merge pull request #18436 from github/version-product-landing-frontmatter
Support conditionals in product landing frontmatter values
2 parents 7b339c4 + 9f00d16 commit 2c0051b

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

layouts/product-landing.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<div class="container-xl px-3 px-md-6 pt-3 pb-2">
1313
<header class="d-lg-flex gutter-lg mb-6">
14-
<div class="col-12 col-lg-6 mb-3 mb-lg-0">
14+
<div class="{% if page.product_video and page.product_video != '' %}col-12 col-lg-6 mb-3 mb-lg-0{% endif %}">
1515
<span class="text-mono text-gray">Product</span>
1616
<h1 class="mb-3 font-mktg">
1717
{{ page.shortTitle }}
@@ -22,24 +22,26 @@ <h1 class="mb-3 font-mktg">
2222
</h1>
2323
<div class="lead-mktg text-gray">{{ page.intro }}</div>
2424

25-
<a href="{{ page.introLinks.quickstart }}" class="btn-mktg btn-large f4 mt-3 mr-3">
25+
{% if page.introLinks.quickstart and page.introLinks.quickstart != '' %}
26+
<a href="/{{ currentLanguage }}{% if currentVersion != 'free-pro-team@latest' %}/{{ currentVersion }}{% endif %}{{ page.introLinks.quickstart }}" class="btn-mktg btn-large f4 mt-3 mr-3">
2627
{% data ui.product_landing.quick_start %}
2728
</a>
29+
{% endif %}
2830

29-
{% if page.introLinks.reference %}
30-
<a href="{{ page.introLinks.reference }}" class="btn-mktg btn-outline-mktg btn-large f4 mt-3 mr-3">
31+
{% if page.introLinks.reference and page.introLinks.reference != '' %}
32+
<a href="/{{ currentLanguage }}{% if currentVersion != 'free-pro-team@latest' %}/{{ currentVersion }}{% endif %}{{ page.introLinks.reference }}" class="btn-mktg btn-outline-mktg btn-large f4 mt-3 mr-3">
3133
{% data ui.product_landing.reference_guides %}
3234
</a>
3335
{% endif %}
3436

35-
{% if page.introLinks.overview %}
36-
<a href="{{ page.introLinks.overview }}" class="btn-mktg btn-outline-mktg btn-large f4 mt-3 mr-3">
37+
{% if page.introLinks.overview and page.introLinks.overview != '' %}
38+
<a href="/{{ currentLanguage }}{% if currentVersion != 'free-pro-team@latest' %}/{{ currentVersion }}{% endif %}{{ page.introLinks.overview }}" class="btn-mktg btn-outline-mktg btn-large f4 mt-3 mr-3">
3739
{% data ui.product_landing.overview %}
3840
</a>
3941
{% endif %}
4042
</div>
4143

42-
{% if page.product_video %}
44+
{% if page.product_video and page.product_video != '' %}
4345
<div class="col-12 col-lg-6">
4446
<div class="position-relative" style="padding-bottom:56.25%;">
4547
{% unless process.env.AIRGAP %}

lib/frontmatter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ const schema = {
109109
},
110110
// Show in `product-landing.html`
111111
product_video: {
112-
type: 'string',
113-
format: 'url'
112+
type: 'string'
114113
},
115114
interactive: {
116115
type: 'boolean'

lib/get-link-data.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path')
22
const findPage = require('./find-page')
33
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
44
const removeFPTFromPath = require('./remove-fpt-from-path')
5+
const renderContent = require('./render-content')
56

67
// rawLinks is an array of paths: [ '/foo' ]
78
// we need to convert it to an array of localized objects: [ { href: '/en/foo', title: 'Foo', intro: 'Description here' } ]
@@ -27,15 +28,17 @@ module.exports = async (rawLinks, context, option = { title: true, intro: true }
2728
}
2829

2930
const processLink = async (link, context, option) => {
30-
const linkPath = link.href || link
31+
const opts = { textOnly: true, encodeEntities: true }
32+
// Parse the link in case it includes Liquid conditionals
33+
const linkPath = await renderContent((link.href || link), context, opts)
34+
if (!linkPath) return null
35+
3136
const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
3237
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))
3338

3439
const linkedPage = findPage(href, context.pages, context.redirects)
3540
if (!linkedPage) return null
3641

37-
const opts = { textOnly: true, encodeEntities: true }
38-
3942
const result = { href, page: linkedPage }
4043

4144
if (option.title) {

lib/page.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class Page {
6868
this.rawPermissions = this.permissions
6969
this.rawLearningTracks = this.learningTracks
7070
this.rawIncludeGuides = this.includeGuides
71+
this.raw_product_video = this.product_video
72+
73+
if (this.introLinks) {
74+
this.introLinks.rawQuickstart = this.introLinks.quickstart
75+
this.introLinks.rawReference = this.introLinks.reference
76+
this.introLinks.rawOverview = this.introLinks.overview
77+
}
7178

7279
// a page should only be available in versions that its parent product is available in
7380
const versionsParentProductIsNotAvailableIn = getApplicableVersions(this.versions, this.fullPath)
@@ -146,6 +153,13 @@ class Page {
146153
this.introPlainText = await renderContent(this.rawIntro, context, { textOnly: true })
147154
this.title = await renderContent(this.rawTitle, context, { textOnly: true, encodeEntities: true })
148155
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })
156+
this.product_video = await renderContent(this.raw_product_video, context, { textOnly: true })
157+
158+
if (this.introLinks) {
159+
this.introLinks.quickstart = await renderContent(this.introLinks.rawQuickstart, context, { textOnly: true })
160+
this.introLinks.reference = await renderContent(this.introLinks.rawReference, context, { textOnly: true })
161+
this.introLinks.overview = await renderContent(this.introLinks.rawOverview, context, { textOnly: true })
162+
}
149163

150164
let markdown = this.mapTopic
151165
// get the map topic child articles from the siteTree

0 commit comments

Comments
 (0)