Skip to content

Commit 062eb62

Browse files
fix : parent frontmatter checks when creating new son or brother
1 parent 167907c commit 062eb62

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/createFamily/commit_info.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
- [ ] fix prevent making children withe "-cluster" name
99
- [ ] اخفي زر الحذف ضمن مجلد الكلستر عند الصغط على زر اليمين
1010
- [ ] READEME.md
11+
- [ ] modifyFirst Template
1112
- [ ] Make TESTS
13+
- [ ] forbid make sons with -cluster name
14+
- [ ] son --> child , father --> parent , brother --> sibling

src/createFamily/templates.ts

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,39 @@ generation: ${generationFromActiveFilePath}
4949

5050
U.bigIF.ELSE(() => {
5151
const frontmatterProperties = this.app.metadataCache.getFileCache(activeFile).frontmatter;
52+
const parentLink = {
53+
wiki: `[[${activeFile?.parent?.name}|${activeFile?.parent?.name}]]`,
54+
absolute: `[[${activeFile?.parent?.path}|${activeFile?.parent?.name}]]`,
55+
bare: `[[${activeFile?.parent?.name}]]`,
56+
frontmatter: frontmatterProperties?.parent
57+
}
58+
function checkParentLinkInFrontmatter(): boolean {
59+
if (parentLink.frontmatter === parentLink.absolute) {
60+
return true
61+
}
62+
if (parentLink.frontmatter === parentLink.bare) {
63+
return true
64+
}
65+
if (parentLink.frontmatter === parentLink.wiki) {
66+
console.warn(parentLink.frontmatter, parentLink.wiki)
67+
return true
68+
}
69+
return false
70+
}
5271
const clusterTagName = activeFile.path.slice(9).replace(/\/.*$/, '').replace(/ /g, "-")
5372
const isClusterTagExist = frontmatterProperties?.tags?.find((tag: string) => tag == `${clusterTagName}`)
54-
const activeFileParentLink = `[[${activeFile?.parent?.path}|${activeFile?.parent?.name}]]`
5573
const sonFileParentLink = `[[${activeFile.path.slice(0, -3)}|${activeFile.basename}]]`
5674
const generationFromActiveFileFrontmatterProperties = frontmatterProperties?.generation
5775
const generationFromActiveFilePath = (activeFile.path.match(/\//g) || []).length - 1 // how many "/" in the path
58-
//FIX how To ensure that a normalized link like [[tt|tt]] always refers to the specific file [[CLUSTERS/tto-cluster/qqq/tt|tt]]
59-
const parentFileLink = frontmatterProperties?.parent
6076

6177
U.bigIF.checkAll([
6278

6379
[!frontmatterProperties, `Please set frontmatter properties`],
6480
[isClusterTagExist == undefined, `You Should add '${clusterTagName}' tag which refers to the containing cluster.`],
65-
[parentFileLink === undefined, "Set the parent property."],
66-
[parentFileLink === null, "The parent property should'nt be empty."],
67-
[parentFileLink === "", "The parent property should'nt be empty."],
68-
[parentFileLink !== activeFileParentLink, `The parent property should be link to '${activeFile.parent?.name}' file.\nlike:${activeFileParentLink}`],
81+
[parentLink.frontmatter === undefined, "Set the parent property."],
82+
[parentLink.frontmatter === null, "The parent property should'nt be empty."],
83+
[parentLink.frontmatter === "", "The parent property should'nt be empty."],
84+
[!checkParentLinkInFrontmatter(), `The parent property should be link to '${activeFile.parent?.name}' file.\nlike:${parentLink.absolute}\nor:${parentLink.wiki}\nor:${parentLink.bare}`],
6985
[!(typeof (generationFromActiveFileFrontmatterProperties) === 'number'), "The Cluster's generation property must be Number.\nChange the property type to Number"],
7086
[generationFromActiveFileFrontmatterProperties == 0, "JUST Clusters's generation property must be 0"],
7187
[generationFromActiveFileFrontmatterProperties !== generationFromActiveFilePath, `The generation property must be ${generationFromActiveFilePath}`],
@@ -89,21 +105,37 @@ generation: ${generationFromActiveFilePath + 1}
89105

90106
U.bigIF.ELSE(() => {
91107
const frontmatterProperties = this.app.metadataCache.getFileCache(activeFile).frontmatter;
108+
const parentLink = {
109+
wiki: `[[${activeFile?.parent?.name}|${activeFile?.parent?.name}]]`,
110+
absolute: `[[${activeFile?.parent?.path}|${activeFile?.parent?.name}]]`,
111+
bare: `[[${activeFile?.parent?.name}]]`,
112+
frontmatter: frontmatterProperties?.parent
113+
}
114+
function checkParentLinkInFrontmatter(): boolean {
115+
if (parentLink.frontmatter === parentLink.absolute) {
116+
return true
117+
}
118+
if (parentLink.frontmatter === parentLink.bare) {
119+
return true
120+
}
121+
if (parentLink.frontmatter === parentLink.wiki) {
122+
console.warn(parentLink.frontmatter, parentLink.wiki)
123+
return true
124+
}
125+
return false
126+
}
92127
const clusterTagName = activeFile.path.slice(9).replace(/\/.*$/, '').replace(/ /g, "-")
93128
const isClusterTagExist = frontmatterProperties?.tags?.find((tag: string) => tag == `${clusterTagName}`)
94-
const activeFileParentLink = `[[${activeFile?.parent?.path}|${activeFile?.parent?.name}]]`
95129
const generationFromActiveFileFrontmatterProperties = frontmatterProperties?.generation
96130
const generationFromActiveFilePath = (activeFile.path.match(/\//g) || []).length - 1 // how many "/" in the path
97-
//FIX how To ensure that a normalized link like [[tt|tt]] always refers to the specific file [[CLUSTERS/tto-cluster/qqq/tt|tt]]
98-
const parentFileLink = frontmatterProperties?.parent
99131

100132
U.bigIF.checkAll([
101133
[!frontmatterProperties, `Please set frontmatter properties`],
102134
[isClusterTagExist == undefined, `You Should add '${clusterTagName}' tag which refers to the containing cluster.`],
103-
[parentFileLink === undefined, "Set the parent property."],
104-
[parentFileLink === null, "The parent property should'nt be empty."],
105-
[parentFileLink === "", "The parent property should'nt be empty."],
106-
[parentFileLink !== activeFileParentLink, `The parent property should be link to '${activeFile.parent?.name}' file.\nlike:${activeFileParentLink}`],
135+
[parentLink.frontmatter === undefined, "Set the parent property."],
136+
[parentLink.frontmatter === null, "The parent property should'nt be empty."],
137+
[parentLink.frontmatter === "", "The parent property should'nt be empty."],
138+
[!checkParentLinkInFrontmatter(), `The parent property should be link to '${activeFile.parent?.name}' file.\nlike:${parentLink.absolute}\nor:${parentLink.wiki}\nor:${parentLink.bare}`],
107139
[!(typeof (generationFromActiveFileFrontmatterProperties) === 'number'), "The Cluster's generation property must be Number.\nChange the property type to Number"],
108140
[generationFromActiveFileFrontmatterProperties == 0, "JUST Clusters's generation property must be 0"],
109141
[generationFromActiveFileFrontmatterProperties !== generationFromActiveFilePath, `The generation property must be ${generationFromActiveFilePath}`],
@@ -116,7 +148,7 @@ generation: ${generationFromActiveFilePath + 1}
116148
`---
117149
tags:
118150
- ${clusterTagName}
119-
parent: "${activeFileParentLink}"
151+
parent: "${parentLink.absolute}"
120152
generation: ${generationFromActiveFilePath}
121153
---
122154
`

0 commit comments

Comments
 (0)