vault backup: 2023-04-03 23:57:57
This commit is contained in:
parent
4571c26e43
commit
8c1706c1d9
5 changed files with 46 additions and 50 deletions
2
.obsidian/plugins/longform/data.json
vendored
2
.obsidian/plugins/longform/data.json
vendored
|
@ -66,7 +66,7 @@
|
||||||
{
|
{
|
||||||
"id": "Projets/Scripts/replaceLinks.js",
|
"id": "Projets/Scripts/replaceLinks.js",
|
||||||
"optionValues": {
|
"optionValues": {
|
||||||
"removeH1": false,
|
"removeH1": true,
|
||||||
"removeFrontmatter": false
|
"removeFrontmatter": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
2
.obsidian/vault-stats.json
vendored
2
.obsidian/vault-stats.json
vendored
|
@ -1 +1 @@
|
||||||
{"history":{"2023-03-01":{"words":845,"characters":1255,"sentences":0,"files":123,"totalWords":29296,"totalCharacters":231518,"totalSentences":821},"2023-03-02":{"words":39,"characters":281,"sentences":0,"files":123,"totalWords":29296,"totalCharacters":231518,"totalSentences":821},"2023-03-03":{"words":644,"characters":3897,"sentences":23,"files":123,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-05":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-06":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-07":{"words":16,"characters":103,"sentences":0,"files":123,"totalWords":29956,"totalCharacters":233253,"totalSentences":844},"2023-03-08":{"words":6,"characters":47,"sentences":1,"files":123,"totalWords":29964,"totalCharacters":233304,"totalSentences":845},"2023-03-10":{"words":15,"characters":102,"sentences":0,"files":124,"totalWords":30010,"totalCharacters":233650,"totalSentences":846},"2023-03-14":{"words":68,"characters":445,"sentences":4,"files":126,"totalWords":30274,"totalCharacters":235667,"totalSentences":857},"2023-03-15":{"words":585,"characters":3851,"sentences":9,"files":129,"totalWords":30998,"totalCharacters":240608,"totalSentences":868},"2023-03-16":{"words":128,"characters":820,"sentences":7,"files":131,"totalWords":31352,"totalCharacters":245878,"totalSentences":877},"2023-03-18":{"words":30,"characters":208,"sentences":0,"files":132,"totalWords":31501,"totalCharacters":247094,"totalSentences":878},"2023-03-19":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":0,"totalCharacters":0,"totalSentences":0},"2023-03-22":{"words":2568,"characters":16916,"sentences":53,"files":133,"totalWords":34073,"totalCharacters":266611,"totalSentences":932},"2023-03-24":{"words":7,"characters":50,"sentences":0,"files":133,"totalWords":34085,"totalCharacters":264035,"totalSentences":932},"2023-03-30":{"words":156,"characters":955,"sentences":9,"files":135,"totalWords":34782,"totalCharacters":265893,"totalSentences":965},"2023-03-31":{"words":129,"characters":798,"sentences":7,"files":135,"totalWords":34911,"totalCharacters":269322,"totalSentences":972},"2023-04-03":{"words":2,"characters":11,"sentences":0,"files":141,"totalWords":35205,"totalCharacters":270668,"totalSentences":988,"totalFootnotes":3,"totalCitations":0,"totalPages":117.19999999999997,"footnotes":0,"citations":0,"pages":0}},"modifiedFiles":{"Aventures/Chapitre 1 - Révolution.md":{"words":{"initial":296,"current":295},"characters":{"initial":2374,"current":2369},"sentences":{"initial":8,"current":8},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":1,"current":1}},"Projets/Absolue Nécessitée/Scenes/Diner chez Althéa.md":{"words":{"initial":0,"current":1},"characters":{"initial":1,"current":8},"sentences":{"initial":1,"current":1},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":0,"current":0}},"Projets/Absolue Nécessitée/Scenes/Assassinat raté.md":{"words":{"initial":0,"current":1},"characters":{"initial":1,"current":5},"sentences":{"initial":1,"current":1},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":0,"current":0}},"Scenes/Diner avec Althéa.md":{"words":{"initial":711,"current":642},"characters":{"initial":4765,"current":3875},"sentences":{"initial":25,"current":24},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":2.4,"current":2.1}}}}
|
{"history":{"2023-03-01":{"words":845,"characters":1255,"sentences":0,"files":123,"totalWords":29296,"totalCharacters":231518,"totalSentences":821},"2023-03-02":{"words":39,"characters":281,"sentences":0,"files":123,"totalWords":29296,"totalCharacters":231518,"totalSentences":821},"2023-03-03":{"words":644,"characters":3897,"sentences":23,"files":123,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-05":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-06":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":29940,"totalCharacters":233149,"totalSentences":844},"2023-03-07":{"words":16,"characters":103,"sentences":0,"files":123,"totalWords":29956,"totalCharacters":233253,"totalSentences":844},"2023-03-08":{"words":6,"characters":47,"sentences":1,"files":123,"totalWords":29964,"totalCharacters":233304,"totalSentences":845},"2023-03-10":{"words":15,"characters":102,"sentences":0,"files":124,"totalWords":30010,"totalCharacters":233650,"totalSentences":846},"2023-03-14":{"words":68,"characters":445,"sentences":4,"files":126,"totalWords":30274,"totalCharacters":235667,"totalSentences":857},"2023-03-15":{"words":585,"characters":3851,"sentences":9,"files":129,"totalWords":30998,"totalCharacters":240608,"totalSentences":868},"2023-03-16":{"words":128,"characters":820,"sentences":7,"files":131,"totalWords":31352,"totalCharacters":245878,"totalSentences":877},"2023-03-18":{"words":30,"characters":208,"sentences":0,"files":132,"totalWords":31501,"totalCharacters":247094,"totalSentences":878},"2023-03-19":{"words":0,"characters":0,"sentences":0,"files":0,"totalWords":0,"totalCharacters":0,"totalSentences":0},"2023-03-22":{"words":2568,"characters":16916,"sentences":53,"files":133,"totalWords":34073,"totalCharacters":266611,"totalSentences":932},"2023-03-24":{"words":7,"characters":50,"sentences":0,"files":133,"totalWords":34085,"totalCharacters":264035,"totalSentences":932},"2023-03-30":{"words":156,"characters":955,"sentences":9,"files":135,"totalWords":34782,"totalCharacters":265893,"totalSentences":965},"2023-03-31":{"words":129,"characters":798,"sentences":7,"files":135,"totalWords":34911,"totalCharacters":269322,"totalSentences":972},"2023-04-03":{"words":9,"characters":64,"sentences":0,"files":142,"totalWords":35205,"totalCharacters":270666,"totalSentences":988,"totalFootnotes":3,"totalCitations":0,"totalPages":117.19999999999997,"footnotes":0,"citations":0,"pages":0}},"modifiedFiles":{"Aventures/Chapitre 1 - Révolution.md":{"words":{"initial":296,"current":295},"characters":{"initial":2374,"current":2369},"sentences":{"initial":8,"current":8},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":1,"current":1}},"Projets/Absolue Nécessitée/Scenes/Diner chez Althéa.md":{"words":{"initial":0,"current":8},"characters":{"initial":1,"current":61},"sentences":{"initial":1,"current":1},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":0,"current":0}},"Projets/Absolue Nécessitée/Scenes/Assassinat raté.md":{"words":{"initial":0,"current":1},"characters":{"initial":1,"current":5},"sentences":{"initial":1,"current":1},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":0,"current":0}},"Scenes/Diner avec Althéa.md":{"words":{"initial":711,"current":642},"characters":{"initial":4765,"current":3875},"sentences":{"initial":25,"current":24},"footnotes":{"initial":0,"current":0},"citations":{"initial":0,"current":0},"pages":{"initial":2.4,"current":2.1}}}}
|
|
@ -1 +1 @@
|
||||||

|
[Diner avec Althéa](../../../Scenes/Diner%20avec%20Althéa.md)
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||

|
[Diner avec Althéa](../../../Scenes/Diner%20avec%20Althéa.md)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
compile
|
compile
|
||||||
};
|
};
|
||||||
|
|
||||||
async function compile(input, context) {
|
async function compile(input, context) {
|
||||||
const files = await getAllFiles(context.app);
|
const files = await getAllFiles(context.app);
|
||||||
console.info("All files: ", files);
|
console.info("All files: ", files);
|
||||||
|
@ -79,8 +78,19 @@ async function compile(input, context) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllFiles(app) {
|
async function getAllFiles(app) {
|
||||||
return app.vault.getFiles();
|
const vaultDir = app.vault.adapter.basePath;
|
||||||
|
const fileData = await app.vault.adapter.fs.readdir(vaultDir, { withFileTypes: true });
|
||||||
|
|
||||||
|
const files = await Promise.all(fileData.map(async (file) => {
|
||||||
|
const filePath = path.join(vaultDir, file.name);
|
||||||
|
if (file.isFile() && path.extname(filePath) === '.md') {
|
||||||
|
const contents = await app.vault.read(file.name);
|
||||||
|
return { name: file.name, contents };
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
return files.filter(file => file !== undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function replaceLinksWithContent(content, metadata, context, files, deep) {
|
async function replaceLinksWithContent(content, metadata, context, files, deep) {
|
||||||
|
@ -93,63 +103,49 @@ async function replaceLinksWithContent(content, metadata, context, files, deep)
|
||||||
|
|
||||||
return allLinks.reduce(async (accProm, item) => {
|
return allLinks.reduce(async (accProm, item) => {
|
||||||
const acc = await accProm;
|
const acc = await accProm;
|
||||||
const [linkedFile, linkedContent] = await getLinkedContent(item.link, context.app, files);
|
|
||||||
|
// Extract the link text and the link path from the link
|
||||||
|
const linkText = item.link;
|
||||||
|
const linkPath = path.isAbsolute(linkText) ? linkText.slice(1) : path.join(path.dirname(metadata.path), linkText);
|
||||||
|
|
||||||
|
const [linkedFile, linkedContent] = await getLinkedContent(linkPath, files);
|
||||||
if (!linkedContent) {
|
if (!linkedContent) {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
const linkedMetadata = getMetadata(linkedFile, context.app);
|
|
||||||
|
|
||||||
let processedLinkedContent;
|
const linkedMetadata = getMetadata(linkedFile.name, context.app);
|
||||||
if (item.type === "embed") {
|
|
||||||
// Replace embed link with embed content
|
|
||||||
const embedProcessor = context.embedProviders.find(provider => provider.shouldProcessLink(item.link));
|
|
||||||
if (embedProcessor) {
|
|
||||||
const embedContent = await embedProcessor.process(item.link);
|
|
||||||
if (embedContent) {
|
|
||||||
processedLinkedContent = embedContent;
|
|
||||||
} else {
|
|
||||||
processedLinkedContent = item.original;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
processedLinkedContent = item.original;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Replace regular link with linked content
|
|
||||||
let contentArray = Array.from(linkedContent);
|
let contentArray = Array.from(linkedContent);
|
||||||
contentArray = removeFrontmatter(contentArray, linkedMetadata.frontmatter, context.optionValues);
|
contentArray = removeFrontmatter(contentArray, linkedMetadata.frontmatter, context.optionValues);
|
||||||
contentArray = removeHeaders(contentArray, linkedMetadata.headings, context.optionValues)
|
contentArray = removeHeaders(contentArray, linkedMetadata.headings, context.optionValues);
|
||||||
const cleanedContent = contentArray.filter(val => val !== null)
|
const cleanedContent = contentArray.filter(val => val !== null)
|
||||||
.join("")
|
.join("")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
processedLinkedContent = await replaceLinksWithContent(cleanedContent, linkedMetadata, context, files, deep + 1);
|
const processedLinkedContent = await replaceLinksWithContent(cleanedContent, linkedMetadata, context, files, deep + 1);
|
||||||
}
|
return acc.replaceAll(item.original, processedLinkedContent);
|
||||||
|
|
||||||
return acc.replaceAll(item.original, processedLinkedContent)
|
|
||||||
}, Promise.resolve(content));
|
}, Promise.resolve(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLinkedContent(linkText, app, files) {
|
async function getLinkedContent(linkPath, files) {
|
||||||
const file = files.find(file => file.basename === linkText);
|
const linkedFile = files.find(file => file.name === linkPath);
|
||||||
if (!file){
|
return linkedFile
|
||||||
const file = await app.vault.getFirstLinkpathDest(linkText);
|
? [linkedFile, linkedFile.contents]
|
||||||
}
|
|
||||||
return file
|
|
||||||
? [file, await app.vault.read(file)]
|
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMetadata(file, app) {
|
function getMetadata(fileName, app) {
|
||||||
return app.metadataCache.getFileCache(file)
|
const file = app.metadataCache.getFirstLinkpathDest(fileName, '');
|
||||||
|
return app.metadataCache.getFileCache(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeHeaders(content, headers, optionValues) {
|
function removeHeaders(content, headings, optionValues) {
|
||||||
if (optionValues.removeH1 && headers) {
|
if (optionValues.removeH1 && headings) {
|
||||||
return headers
|
return headings
|
||||||
.filter(header => header.level === 1)
|
.filter(header => header.level === 1)
|
||||||
.reduce((acc, header) => {
|
.reduce((acc, header) => {
|
||||||
return removeFromTextArray(acc, header.position)
|
return removeFromTextArray(acc, header.position);
|
||||||
}, content)
|
}, content);
|
||||||
} else {
|
} else {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -164,5 +160,5 @@ function removeFrontmatter(content, frontmatter, optionValues) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFromTextArray(text, position) {
|
function removeFromTextArray(text, position) {
|
||||||
return text.map((val, i) => i >= position.start.offset && i < position.end.offset ? null : val)
|
return text.map((val, i) => i >= position.start.offset && i < position.end.offset ? null : val);
|
||||||
}
|
}
|
Loading…
Reference in a new issue