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

find-page.js 1.3 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
  1. const path = require('path')
  2. const Page = require('../../lib/page')
  3. const findPage = require('../../lib/find-page')
  4. describe('find page', () => {
  5. jest.setTimeout(1000 * 1000)
  6. test('falls back to the English page if it can\'t find a localized page', async () => {
  7. const page = await Page.init({
  8. relativePath: 'page-that-does-not-exist-in-translations-dir.md',
  9. basePath: path.join(__dirname, '../fixtures'),
  10. languageCode: 'en'
  11. })
  12. const englishPermalink = page.permalinks[0].href
  13. const japanesePermalink = englishPermalink.replace('/en/', '/ja/')
  14. // add named keys
  15. const pageMap = {
  16. [englishPermalink]: page
  17. }
  18. const localizedPage = findPage(japanesePermalink, pageMap, {})
  19. expect(typeof localizedPage.title).toBe('string')
  20. })
  21. test('follows redirects', async () => {
  22. const page = await Page.init({
  23. relativePath: 'page-with-redirects.md',
  24. basePath: path.join(__dirname, '../fixtures'),
  25. languageCode: 'en'
  26. })
  27. const englishPermalink = page.permalinks[0].href
  28. const redirectToFind = '/some-old-path'
  29. // add named keys
  30. const pageMap = {
  31. [englishPermalink]: page
  32. }
  33. const redirectedPage = findPage(redirectToFind, pageMap, page.buildRedirects())
  34. expect(typeof redirectedPage.title).toBe('string')
  35. })
  36. })
Tip!

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

Comments

Loading...