Skip to content

Commit a9232f5

Browse files
committed
feat: auto connect markdown layout
1 parent 64ae913 commit a9232f5

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"types": "src/index.ts",
55
"main": "built/index.js",
66
"scripts": {

src/utils/analyse-project.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IProjectInfo } from "./analyse-project-interface"
55
import {
66
configPaths,
77
layoutsPath,
8-
markdownPath,
8+
markdownLayoutPath,
99
notFoundPath,
1010
pagesPath,
1111
storesPath
@@ -30,7 +30,7 @@ export const analyseProject = async (projectRootPath: string) => {
3030
info.has404File = true
3131
}
3232

33-
if (fs.existsSync(path.join(projectRootPath, path.format(markdownPath)))) {
33+
if (fs.existsSync(path.join(projectRootPath, path.format(markdownLayoutPath)))) {
3434
info.hasMarkdownFile = true
3535
}
3636

src/utils/create-entry.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { md5 } from "./md5"
77
import { IProjectConfig } from "./project-config-interface"
88
import {
99
helperPath,
10-
markdownPath,
10+
markdownLayoutPath,
1111
markdownTempPath,
1212
notFoundPath,
1313
tempJsEntryPath
1414
} from "./structor-config"
1515

16-
const MARKDOWN_TEMPLATE_NAME = "MarkdownTemplate"
16+
const MARKDOWN_LAYOUT_NAME = "MarkdownTemplate"
1717
const MARKDOWN_WRAPPER = "MarkdownWrapper"
1818

1919
interface IEntryText {
@@ -135,8 +135,17 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
135135

136136
// Set markdownImporter
137137
if (info.hasMarkdownFile) {
138-
const markdownRelativePath = path.relative(tempJsEntryPath.dir, path.join(markdownPath.dir, markdownPath.name))
139-
entryText.markdownImporter += `import ${MARKDOWN_TEMPLATE_NAME} from "${markdownRelativePath}"\n`
138+
const markdownRelativePath = path.relative(tempJsEntryPath.dir, path.join(markdownLayoutPath.dir, markdownLayoutPath.name))
139+
140+
if (info.stores.length === 0) {
141+
entryText.markdownImporter = `import ${MARKDOWN_LAYOUT_NAME} from "${markdownRelativePath}"\n`
142+
} else {
143+
const markdownLayoutPure = `${MARKDOWN_LAYOUT_NAME}Pure`
144+
entryText.markdownImporter = `
145+
import ${markdownLayoutPure} from "${markdownRelativePath}"
146+
const ${MARKDOWN_LAYOUT_NAME} = Connect()(${markdownLayoutPure})
147+
`
148+
}
140149
}
141150

142151
// Set routes
@@ -228,9 +237,9 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
228237
entryText.pageImporter += `
229238
import ${tempComponentName} from "${markdownTsAbsolutePathWithoutExt}"
230239
const ${componentName} = () => (
231-
<${MARKDOWN_TEMPLATE_NAME}>
240+
<${MARKDOWN_LAYOUT_NAME}>
232241
${wrapperStr}
233-
</${MARKDOWN_TEMPLATE_NAME}>
242+
</${MARKDOWN_LAYOUT_NAME}>
234243
)
235244
`
236245
} else {
@@ -246,9 +255,9 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
246255
importCode = `
247256
import("${markdownTsAbsolutePathWithoutExt}").then(code => {
248257
return () => (
249-
<${MARKDOWN_TEMPLATE_NAME}>
258+
<${MARKDOWN_LAYOUT_NAME}>
250259
${wrapperStr}
251-
</${MARKDOWN_TEMPLATE_NAME}>
260+
</${MARKDOWN_LAYOUT_NAME}>
252261
)
253262
})
254263
`

src/utils/structor-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const layoutsPath = {
4242
ext: ".tsx"
4343
}
4444

45-
export const markdownPath = {
45+
export const markdownLayoutPath = {
4646
dir: layoutsPath.dir,
4747
name: "markdown",
4848
ext: ".tsx"

0 commit comments

Comments
 (0)