-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert: "refactor: remove extra methods"
This reverts commit a6fe43d.
- Loading branch information
1 parent
46bba07
commit 880ccba
Showing
9 changed files
with
159 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## GetPagesPath | ||
|
||
<ul> | ||
<li v-for="path in pagesPath"> | ||
{{path}} | ||
</li> | ||
</ul> | ||
|
||
<script setup> | ||
import { getPagesPath } from 'vuepress/client' | ||
|
||
const pagesPath = getPagesPath(); | ||
</script> |
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 @@ | ||
# isPageExist | ||
|
||
- /: {{isPageExist('/')}} | ||
- /README.md: {{isPageExist('/README.md')}} | ||
- /index.html: {{isPageExist('/index.html')}} | ||
- /not-exist: {{isPageExist('/not-exist')}} | ||
- /not-exist.html: {{isPageExist('/not-exist.html')}} | ||
- /not-exist.md: {{isPageExist('/not-exist.md')}} | ||
- /routes/non-ascii-paths/中文目录名/中文文件名.md: {{isPageExist('/routes/non-ascii-paths/中文目录名/中文文件名.md')}} | ||
- /routes/non-ascii-paths/中文目录名/中文文件名.html: {{isPageExist('/routes/non-ascii-paths/中文目录名/中文文件名.html')}} | ||
- {{encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md')}}: {{isPageExist(encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md'))}} | ||
- {{encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html')}}: {{isPageExist(encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'))}} | ||
- /zh/: {{isPageExist('/zh/')}} | ||
- /zh: {{isPageExist('/zh')}} | ||
|
||
<script setup> | ||
import { isPageExist } from 'vuepress/client' | ||
</script> |
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,9 @@ | ||
## resolve | ||
|
||
- Clean url: {{JSON.stringify(resolve('/page-data/meta'))}} | ||
- HTML: {{JSON.stringify(resolve('/page-data/meta.html'))}} | ||
- Markdown: {{JSON.stringify(resolve('/page-data/meta.md'))}} | ||
|
||
<script setup> | ||
import { resolve } from 'vuepress/client' | ||
</script> |
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,45 @@ | ||
it('getPagesPath', () => { | ||
cy.visit('/routes/get-pages-path.html') | ||
|
||
const paths = [ | ||
'/', | ||
// '/layouts/custom-layout.html', | ||
// '/layouts/layout.html', | ||
// '/markdown/anchors.html', | ||
// '/markdown/code-blocks.html', | ||
// '/markdown/emoji.html', | ||
// '/markdown/import-code-blocks.html', | ||
// '/markdown/links/bar.html', | ||
// '/markdown/links/baz.html', | ||
// '/markdown/links/foo.html', | ||
// '/markdown/toc.html', | ||
// '/markdown/vue-components.html', | ||
// '/page-data/frontmatter.html', | ||
// '/page-data/headers.html', | ||
// '/page-data/lang.html', | ||
// '/page-data/meta.html', | ||
// '/page-data/permalink.html', | ||
// '/page-data/title-from-frontmatter.html', | ||
// '/page-data/title-from-h1.html', | ||
// '/routes/non-ascii-paths/', | ||
// '/routes/non-ascii-paths/%E4%B8%AD%E6%96%87%E7%9B%AE%E5%BD%95%E5%90%8D/%E4%B8%AD%E6%96%87%E6%96%87%E4%BB%B6%E5%90%8D.html', | ||
// '/routes/get-pages-path.html', | ||
// '/routes/resolve.html', | ||
// '/routes/is-page-exist.html', | ||
// '/zh/', | ||
// '/404.html', | ||
] | ||
|
||
const pagePaths: string[] = [] | ||
|
||
// eslint-disable-next-line cypress/unsafe-to-chain-command | ||
cy.get('.e2e-theme-content ul li') | ||
.each((el) => { | ||
pagePaths.push(el.text()) | ||
}) | ||
.then(() => { | ||
paths.forEach((path) => { | ||
expect(pagePaths.includes(path)).to.equal(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
it('isPageExist', () => { | ||
cy.visit('/routes/is-page-exist.html') | ||
|
||
const results = [ | ||
'/: true', | ||
'/README.md: true', | ||
'/index.html: true', | ||
'/not-exist: false', | ||
'/not-exist.html: false', | ||
'/not-exist.md: false', | ||
'/routes/non-ascii-paths/中文目录名/中文文件名.md: true', | ||
'/routes/non-ascii-paths/中文目录名/中文文件名.html: true', | ||
`${encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.md')}: true`, | ||
`${encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html')}: true`, | ||
'/zh/: true', | ||
'/zh: false', | ||
] | ||
|
||
cy.get('.e2e-theme-content ul li').each((el) => { | ||
expect(results.includes(el.text())).to.equal(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
it('resolve', () => { | ||
cy.visit('/routes/resolve.html') | ||
const result = { path: '/page-data/meta.html', meta: { a: 0, b: 2, c: 3 } } | ||
|
||
cy.get('.e2e-theme-content ul li').each((el) => { | ||
expect(JSON.parse(/: (\{.*\})\s*$/.exec(el.text())![1])).to.deep.include( | ||
result, | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './defineClientConfig.js' | ||
export * from './router.js' | ||
export * from './withBase.js' |
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,38 @@ | ||
import type { PagesMap } from '@internal/pagesMap' | ||
import { pagesMap, redirectsMap } from '../composables/index.js' | ||
import { resolvers } from '../resolvers.js' | ||
|
||
/** | ||
* Get all paths of pages | ||
* | ||
* @returns all paths of pages | ||
*/ | ||
export const getPagesPath = (): string[] => Array.from(pagesMap.value.keys()) | ||
|
||
/** | ||
* Check whether the page exists | ||
* | ||
* @param path path of the page | ||
* @returns whether the page exists | ||
*/ | ||
export const isPageExist = (path: string): boolean => | ||
pagesMap.value.has( | ||
resolvers.resolvePagePath(pagesMap.value, redirectsMap.value, path), | ||
) | ||
|
||
/** | ||
* Resolve final path and meta with given path | ||
* | ||
* @param path path of the page | ||
* @returns resolved path and meta | ||
*/ | ||
export const resolve = <PageMeta>( | ||
path: string, | ||
): { path: string; meta: PageMeta | null } => { | ||
path = resolvers.resolvePagePath(pagesMap.value, redirectsMap.value, path) | ||
|
||
return { | ||
path, | ||
meta: (pagesMap.value as PagesMap<PageMeta>).get(path)?.meta ?? null, | ||
} | ||
} |