-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathfrontmatter-video-transcripts.ts
More file actions
89 lines (82 loc) · 3.2 KB
/
frontmatter-video-transcripts.ts
File metadata and controls
89 lines (82 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { addError } from 'markdownlint-rule-helpers'
import path from 'path'
import { getFrontmatter } from '../helpers/utils'
import type { RuleParams, RuleErrorCallback, Rule } from '@/content-linter/types'
interface Frontmatter {
product_video?: string
product_video_transcript?: string
title?: string
layout?: string
[key: string]: any
}
export const frontmatterVideoTranscripts: Rule = {
names: ['GHD011', 'frontmatter-video-transcripts'],
description: 'Video transcript must be configured correctly',
tags: ['frontmatter', 'feature', 'video-transcripts'],
function: (params: RuleParams, onError: RuleErrorCallback) => {
const filepath = params.name
const fm = getFrontmatter(params.lines) as Frontmatter | null
if (!fm) return
const isTranscriptContent =
filepath.includes('video-transcripts') && path.basename(filepath) !== 'index.md'
// Video transcripts must have specific frontmatter properties
if (isTranscriptContent) {
if (!fm.product_video) {
const lineNumber = 1
addError(
onError,
lineNumber,
'Video transcripts must contain an reference to the video being transcribed. Ensure the frontmatter property `product_video` is set to the path of the video.',
null, // No context because the property is missing
null, // No range for missing line
null, // No fix possible
)
}
if (fm.title && !fm.title.startsWith('Transcript - ')) {
const lineNumber = params.lines.findIndex((line) => line.startsWith('title:')) + 1
const lineContent = params.lines[lineNumber - 1]
addError(
onError,
lineNumber,
'Video transcript pages must prepend the frontmatter title property with "Transcript - ".',
lineContent,
[1, lineContent.length],
null, // No fix possible
)
}
}
// A landing page that defines either a product_video or
// product_video_transcript frontmatter must define both
if (fm.layout === 'product-landing' && (fm.product_video || fm.product_video_transcript)) {
const lineNumber =
params.lines.findIndex(
(line) =>
line.startsWith('product_video_transcript:') || line.startsWith('product_video:'),
) + 1
const lineContent = params.lines[lineNumber - 1]
if (
!fm.product_video_transcript ||
!fm.product_video_transcript.startsWith('/video-transcripts/')
) {
addError(
onError,
lineNumber,
'Videos on product landing pages must contain a video transcript. Ensure the frontmatter property `product_video_transcript` is set to the path of the transcript in the video-transcript directory.',
lineContent,
[1, lineContent.length],
null, // No fix possible
)
}
if (!fm.product_video) {
addError(
onError,
lineNumber,
'Video transcripts on product landing pages must have a product video. Ensure the frontmatter property `product_video` is set to the path of the video.',
lineContent,
[1, lineContent.length],
null, // No fix possible
)
}
}
},
}