Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
haouarihk authored Jan 16, 2024
1 parent 5934aad commit 315b0f1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
18 changes: 9 additions & 9 deletions manifest.json
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"
}
66 changes: 66 additions & 0 deletions prompts/conceptLinker.md
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}}
14 changes: 0 additions & 14 deletions prompts/getExample.md

This file was deleted.

0 comments on commit 315b0f1

Please sign in to comment.