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

toc-links.js 1.4 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
  1. const { loadPages } = require('../../lib/pages')
  2. const renderContent = require('../../lib/render-content')
  3. const allVersions = Object.keys(require('../../lib/all-versions'))
  4. describe('toc links', () => {
  5. jest.setTimeout(3 * 60 * 1000)
  6. test('every toc link works without redirects', async () => {
  7. const pages = await loadPages()
  8. const englishIndexPages = pages
  9. .filter(page => page.languageCode === 'en' && page.relativePath.endsWith('index.md'))
  10. const issues = []
  11. for (const pageVersion of allVersions) {
  12. for (const page of englishIndexPages) {
  13. // skip page if it doesn't have a permalink for the current product version
  14. if (!page.permalinks.some(permalink => permalink.pageVersion === pageVersion)) continue
  15. // build fake context object for rendering the page
  16. const context = {
  17. page,
  18. pages,
  19. redirects: {},
  20. currentLanguage: 'en',
  21. currentVersion: pageVersion
  22. }
  23. // ensure all toc pages can render
  24. try {
  25. await renderContent(page.markdown, context)
  26. } catch (err) {
  27. issues.push({
  28. 'TOC path': page.relativePath,
  29. error: err.message,
  30. pageVersion
  31. })
  32. }
  33. }
  34. }
  35. const message = 'broken link in a TOC: ' + JSON.stringify(issues, null, 2)
  36. expect(issues.length, message).toBe(0)
  37. })
  38. })
Tip!

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

Comments

Loading...