MCPcopy Index your code
hub / github.com/github/docs / Permalink

Class Permalink

lib/permalink.js:30–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28]
29*/
30class Permalink {
31 constructor(languageCode, pageVersion, relativePath, title) {
32 this.languageCode = languageCode
33 this.pageVersion = pageVersion
34 this.relativePath = relativePath
35 this.title = title
36
37 const permalinkSuffix = this.constructor.relativePathToSuffix(relativePath)
38
39 this.hrefWithoutLanguage = removeFPTFromPath(
40 path.posix.join('/', pageVersion, permalinkSuffix)
41 ).replace(patterns.trailingSlash, '$1')
42 this.href = `/${languageCode}${
43 this.hrefWithoutLanguage === '/' ? '' : this.hrefWithoutLanguage
44 }`
45
46 return this
47 }
48
49 static derive(languageCode, relativePath, title, applicableVersions) {
50 assert(relativePath, 'relativePath is required')
51 assert(languageCode, 'languageCode is required')
52
53 const permalinks = applicableVersions.map((pageVersion) => {
54 return new Permalink(languageCode, pageVersion, relativePath, title)
55 })
56
57 return permalinks
58 }
59
60 static relativePathToSuffix(relativePath) {
61 return '/' + relativePath.replace('index.md', '').replace('.md', '')
62 }
63}
64
65export default Permalink

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected