forked from tinacms/tina.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29b6828
commit cad0434
Showing
8 changed files
with
2,106 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ jobs: | |
run: | | ||
yarn install | ||
yarn build --if-present | ||
yarn lint | ||
yarn test | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function createJestConfig(pack) { | ||
return { | ||
verbose: true, | ||
transform: { | ||
'.(ts|tsx)': 'ts-jest', | ||
}, | ||
testRegex: '(\\.test)\\.(ts|tsx|js)$', | ||
modulePaths: ['<rootDir>/', '<rootDir>/node_modules/'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js'], | ||
displayName: pack.name, | ||
name: pack.name, | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': | ||
'<rootDir>/../../__mocks__/fileMock.js', | ||
'\\.(css|scss)$': 'identity-obj-proxy', | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const createJestConfig = require("./create.jest.config.js"); | ||
const pack = require("./package"); | ||
|
||
module.exports = createJestConfig(pack); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
getDynamicPath, | ||
BLOG_PATH, | ||
BLOG_INDEX_PATH, | ||
DOCS_PATH, | ||
} from './getDynamicPath' | ||
|
||
describe('getDynamicPath', () => { | ||
describe('with static path', () => { | ||
const STATIC_URL = '/teams' | ||
it('should return original path', () => { | ||
const url = getDynamicPath(STATIC_URL) | ||
expect(url).toEqual(STATIC_URL) | ||
}) | ||
|
||
it('should return original path with root', () => { | ||
const url = getDynamicPath('/') | ||
expect(url).toEqual('/') | ||
}) | ||
}) | ||
describe('with dynamic path', () => { | ||
describe('- blog post', () => { | ||
it('should return blog path', () => { | ||
const url = getDynamicPath('/blog/heres-a-post') | ||
expect(url).toEqual(BLOG_PATH) | ||
}) | ||
}) | ||
describe('- blog index', () => { | ||
it('should return blog index path', () => { | ||
const url = getDynamicPath('/blog/page/3') | ||
expect(url).toEqual(BLOG_INDEX_PATH) | ||
}) | ||
}) | ||
describe('- docs', () => { | ||
it('should return docs path', () => { | ||
const url = getDynamicPath('/docs/sub/heres-a-doc') | ||
expect(url).toEqual(DOCS_PATH) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//used to create Next links to actual page layout path | ||
|
||
export const DOCS_PATH = '/docs/[...slug]' | ||
export const BLOG_INDEX_PATH = '/blog/page/[page_index]' | ||
export const BLOG_PATH = '/blog/[slug]' | ||
|
||
export function getDynamicPath(url: string) { | ||
const docsPattern = new RegExp('(.)?/docs/(.)+') | ||
if (docsPattern.test(url)) { | ||
return '/docs/[...slug]' | ||
} | ||
|
||
const blogIndexPattern = new RegExp('(.)?/blog/page/[0-9]+') | ||
if (blogIndexPattern.test(url)) { | ||
return '/blog/page/[page_index]' | ||
} | ||
|
||
const blogPattern = new RegExp('(.)?/blog/(.)+') | ||
if (blogPattern.test(url)) { | ||
return '/blog/[slug]' | ||
} | ||
|
||
return url | ||
} |
Oops, something went wrong.