MCPcopy
hub / github.com/github/docs / constructor

Method constructor

lib/page.js:70–136  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

68 }
69
70 constructor(opts) {
71 if (opts.frontmatterErrors && opts.frontmatterErrors.length) {
72 throw new FrontmatterErrorsError(
73 `${opts.frontmatterErrors.length} frontmatter errors trying to load ${opts.fullPath}`,
74 opts.frontmatterErrors
75 )
76 }
77 delete opts.frontmatterErrors
78 Object.assign(this, { ...opts })
79
80 // Store raw data so we can cache parsed versions
81 this.rawIntro = this.intro
82 this.rawTitle = this.title
83 this.rawShortTitle = this.shortTitle
84 this.rawProduct = this.product
85 this.rawPermissions = this.permissions
86 this.rawLearningTracks = this.learningTracks
87 this.rawIncludeGuides = this.includeGuides
88 this.rawIntroLinks = this.introLinks
89
90 // Is this the Homepage or a Product, Category, Topic, or Article?
91 this.documentType = getDocumentType(this.relativePath)
92
93 // Get array of versions that the page is available in for fast lookup
94 this.applicableVersions = getApplicableVersions(this.versions, this.fullPath)
95
96 // Only check the parent product ID for English because if a top-level
97 // product is edited in English, it will fail for translations until
98 // the next translation pipeline PR gets a chance to catch up.
99 if (this.languageCode === 'en') {
100 // a page should only be available in versions that its parent product is available in
101 const versionsParentProductIsNotAvailableIn = this.applicableVersions
102 // only the homepage will not have this.parentProduct
103 .filter(
104 (availableVersion) =>
105 this.parentProduct && !this.parentProduct.versions.includes(availableVersion)
106 )
107
108 if (versionsParentProductIsNotAvailableIn.length) {
109 throw new Error(
110 `\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`
111 )
112 }
113 }
114
115 // derive array of Permalink objects
116 this.permalinks = Permalink.derive(
117 this.languageCode,
118 this.relativePath,
119 this.title,
120 this.applicableVersions
121 )
122
123 if (this.relativePath.endsWith('index.md')) {
124 // get an array of linked items in product and category TOCs
125 this.tocItems = getTocItems(this)
126 }
127

Callers

nothing calls this directly

Calls 4

getDocumentTypeFunction · 0.85
getApplicableVersionsFunction · 0.85
deriveMethod · 0.80
getTocItemsFunction · 0.70

Tested by

no test coverage detected