generated from text-gen/templates-package
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
23 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"packageId": "Put_Package_Id_Here", | ||
"name": "Name of your package", | ||
"packageId": "Experimental", | ||
"name": "Experimental Package", | ||
"version": "0.0.1", | ||
"minTextGeneratorVersion": "0.1.0", | ||
"description": "The description of the content of this package", | ||
"author": "Your name", | ||
"tags": "writing, brainstorming", | ||
"authorUrl": "Support URL", | ||
"repo": "username/repo" | ||
} | ||
"minTextGeneratorVersion": "0.6.6", | ||
"description": "Contains experimental templates", | ||
"author": "Noureddine", | ||
"tags": "experiments", | ||
"authorUrl": "https://www.buymeacoffee.com/haouarine", | ||
"repo": "text-gen/experimental-package" | ||
} |
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,66 @@ | ||
--- | ||
promptId: conceptLinker | ||
name: 🗞️conceptLinker | ||
description: Generate notes and links them from the current note's words | ||
author: Noureddine | ||
tags: | ||
- notes | ||
- linking | ||
- brainStorming | ||
version: 0.0.1 | ||
disableProvider: true | ||
commands: | ||
- generate | ||
--- | ||
```handlebars | ||
``` | ||
*** | ||
*** | ||
{{#script}} | ||
```js | ||
// Uses an external function 'gen' to generate concepts and their definitions | ||
async function extractAndDefineConcepts(text) { | ||
const prompt = `Extract concepts from the following content and define them. Do not refer to the current note. do not refer to already refered concepts(contained in []). Return a json Record<name, definition>. Ensure the 'name' is exactly as it appears in the text, without any modifications: \n${text.replace(/\[\[.*?\]\]/g, '')}`; | ||
|
||
const conceptData = await genJSON(prompt); // returns object | ||
|
||
return Object.entries(conceptData).map(([name, definition]) => ({name, definition})); | ||
} | ||
|
||
function replaceConceptsWithLinks(text, concepts) { | ||
let modifiedText = text; | ||
concepts.forEach(concept => { | ||
modifiedText = modifiedText.replace(new RegExp(concept.name, 'g'), `[[${concept.name}]]`); | ||
}); | ||
return modifiedText; | ||
} | ||
|
||
async function createConceptPages(concepts) { | ||
const currentFolder = app.workspace.getActiveFile().parent.path; | ||
for (const concept of concepts) { | ||
const conceptFilePath = `${currentFolder}/${concept.name}.md`; | ||
if (!await app.vault.exists(conceptFilePath)) { | ||
await app.vault.create(conceptFilePath, `# ${concept.name}\n\n${concept.definition}`); | ||
} | ||
} | ||
} | ||
|
||
async function extractConcepts() { | ||
const activeFile = app.workspace.getActiveFile(); | ||
if (!activeFile) return; | ||
|
||
const fileContent = (""+await app.vault.read(activeFile)) | ||
|
||
const concepts = await extractAndDefineConcepts(fileContent); | ||
|
||
const modifiedContent = replaceConceptsWithLinks(fileContent, concepts); | ||
console.log({modifiedContent}) | ||
await app.vault.modify(activeFile, modifiedContent); | ||
|
||
await createConceptPages(concepts); | ||
} | ||
|
||
await extractConcepts(); | ||
return ""; | ||
``` | ||
{{/script}} |
This file was deleted.
Oops, something went wrong.