Skip to content

Commit 64f2d63

Browse files
committed
Add support for defaultPlatform frontmatter
TODO: add 'all' to frontmatter schema enum?
1 parent 5522b58 commit 64f2d63

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

includes/article.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ <h1 class="border-bottom-0">{{ page.title }}</h1>
2929
{% endif %}
3030

3131
{% if page.includesPlatformSpecificContent %}
32-
<nav class="UnderlineNav my-3">
32+
<nav class="UnderlineNav my-3"
33+
{%- if page.defaultPlatform %} data-default-platform="{{ page.defaultPlatform }}"{% endif %}>
3334
<div class="UnderlineNav-body">
3435
<a href="#" class="UnderlineNav-item platform-switcher" data-platform="mac">Mac</a>
3536
<a href="#" class="UnderlineNav-item platform-switcher" data-platform="windows">Windows</a>

javascripts/display-platform-specific-content.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const detectedPlatforms = new Set()
55
// Emphasize content for the visitor's OS (inferred from user agent string)
66

77
export default function displayPlatformSpecificContent () {
8-
let platform = getPlatformFromUserAgent()
8+
let platform = getDefaultPlatform() || getPlatformFromUserAgent()
99

1010
// adjust platform names to fit existing mac/windows/linux scheme
1111
if (!platform) platform = 'mac' // default to 'mac' on mobile
@@ -78,6 +78,11 @@ function detectPlatforms (el) {
7878
})
7979
}
8080

81+
function getDefaultPlatform () {
82+
const el = document.querySelector("[data-default-platform]")
83+
if (el) return el.dataset.defaultPlatform
84+
}
85+
8186
function switcherLinks () {
8287
return Array.from(document.querySelectorAll('a.platform-switcher'))
8388
}

lib/frontmatter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ const schema = {
9595
},
9696
interactive: {
9797
type: 'boolean'
98+
},
99+
// Platform-specific content preference
100+
defaultPlatform: {
101+
type: 'string',
102+
enum: [ 'mac', 'windows', 'linux' ] // TODO: add 'all'?
98103
}
99104
}
100105
}

0 commit comments

Comments
 (0)