Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

permalink.js 2.0 KB

You have to be logged in to leave a comment. Sign In
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
  1. const assert = require('assert')
  2. const path = require('path')
  3. const patterns = require('./patterns')
  4. const getApplicableVersions = require('./get-applicable-versions')
  5. const allVersions = require('./all-versions')
  6. const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
  7. const removeFPTFromPath = require('./remove-fpt-from-path')
  8. class Permalink {
  9. constructor (languageCode, pageVersion, relativePath, title) {
  10. this.languageCode = languageCode
  11. this.pageVersion = pageVersion
  12. this.relativePath = relativePath
  13. this.title = title
  14. const permalinkSuffix = this.constructor.relativePathToSuffix(relativePath)
  15. this.href = removeFPTFromPath(path.posix.join('/', languageCode, pageVersion, permalinkSuffix))
  16. .replace(patterns.trailingSlash, '$1')
  17. this.pageVersionTitle = allVersions[pageVersion].versionTitle
  18. return this
  19. }
  20. static derive (languageCode, relativePath, title, frontmatterVersions) {
  21. assert(relativePath, 'relativePath is required')
  22. assert(languageCode, 'languageCode is required')
  23. const applicableVersions = getApplicableVersions(frontmatterVersions, path.join(languageCode, relativePath))
  24. const permalinks = applicableVersions
  25. // skip the Dotcom homepage here because a special homepage permalink is added below
  26. .filter(pageVersion => !(pageVersion === nonEnterpriseDefaultVersion && relativePath === 'index.md'))
  27. .map(pageVersion => {
  28. return new Permalink(languageCode, pageVersion, relativePath, title)
  29. })
  30. // special permalink for homepage
  31. if (relativePath === 'index.md') {
  32. const homepagePermalink = {
  33. ...permalinks[0],
  34. href: '/' + languageCode,
  35. pageVersion: 'homepage',
  36. pageVersionTitle: permalinks[0].title,
  37. homepage: true
  38. }
  39. permalinks.push(homepagePermalink)
  40. }
  41. return permalinks
  42. }
  43. static relativePathToSuffix (relativePath) {
  44. return '/' + relativePath
  45. .replace('index.md', '')
  46. .replace('.md', '')
  47. }
  48. }
  49. module.exports = Permalink
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...