vault backup: 2023-04-03 23:57:57

This commit is contained in:
Lucas 2023-04-03 23:57:57 +02:00
parent 4571c26e43
commit 8c1706c1d9
5 changed files with 46 additions and 50 deletions

View file

@ -66,7 +66,7 @@
{
"id": "Projets/Scripts/replaceLinks.js",
"optionValues": {
"removeH1": false,
"removeH1": true,
"removeFrontmatter": false
}
},

View file

@ -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}}}}

View file

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

View file

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

View file

@ -66,7 +66,6 @@ module.exports = {
*/
compile
};
async function compile(input, context) {
const files = await getAllFiles(context.app);
console.info("All files: ", files);
@ -79,8 +78,19 @@ async function compile(input, context) {
)
}
function getAllFiles(app) {
return app.vault.getFiles();
async function getAllFiles(app) {
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) {
@ -93,63 +103,49 @@ async function replaceLinksWithContent(content, metadata, context, files, deep)
return allLinks.reduce(async (accProm, item) => {
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) {
return acc;
}
const linkedMetadata = getMetadata(linkedFile, context.app);
let processedLinkedContent;
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);
contentArray = removeFrontmatter(contentArray, linkedMetadata.frontmatter, context.optionValues);
contentArray = removeHeaders(contentArray, linkedMetadata.headings, context.optionValues)
const cleanedContent = contentArray.filter(val => val !== null)
.join("")
.trim();
const linkedMetadata = getMetadata(linkedFile.name, context.app);
processedLinkedContent = await replaceLinksWithContent(cleanedContent, linkedMetadata, context, files, deep + 1);
}
let contentArray = Array.from(linkedContent);
contentArray = removeFrontmatter(contentArray, linkedMetadata.frontmatter, context.optionValues);
contentArray = removeHeaders(contentArray, linkedMetadata.headings, context.optionValues);
const cleanedContent = contentArray.filter(val => val !== null)
.join("")
.trim();
return acc.replaceAll(item.original, processedLinkedContent)
const processedLinkedContent = await replaceLinksWithContent(cleanedContent, linkedMetadata, context, files, deep + 1);
return acc.replaceAll(item.original, processedLinkedContent);
}, Promise.resolve(content));
}
async function getLinkedContent(linkText, app, files) {
const file = files.find(file => file.basename === linkText);
if (!file){
const file = await app.vault.getFirstLinkpathDest(linkText);
}
return file
? [file, await app.vault.read(file)]
async function getLinkedContent(linkPath, files) {
const linkedFile = files.find(file => file.name === linkPath);
return linkedFile
? [linkedFile, linkedFile.contents]
: [];
}
function getMetadata(file, app) {
return app.metadataCache.getFileCache(file)
function getMetadata(fileName, app) {
const file = app.metadataCache.getFirstLinkpathDest(fileName, '');
return app.metadataCache.getFileCache(file);
}
function removeHeaders(content, headers, optionValues) {
if (optionValues.removeH1 && headers) {
return headers
function removeHeaders(content, headings, optionValues) {
if (optionValues.removeH1 && headings) {
return headings
.filter(header => header.level === 1)
.reduce((acc, header) => {
return removeFromTextArray(acc, header.position)
}, content)
return removeFromTextArray(acc, header.position);
}, content);
} else {
return content;
}
@ -164,5 +160,5 @@ function removeFrontmatter(content, frontmatter, optionValues) {
}
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);
}