Skip to content

Commit

Permalink
prettify and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeGirlMurph committed Jun 8, 2024
1 parent 7ab250e commit e2e2d5b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
1 change: 0 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default defineConfig({
lang: "en-US",
base: "/obsidian-wikipedia-search/",


themeConfig: {
search: {
provider: "local",
Expand Down
Binary file removed docs/public/workflow-optimizations.png
Binary file not shown.
4 changes: 0 additions & 4 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ You can also use [Templater](https://github.com/SilentVoid13/Templater) Syntax i

## Workflow optimization settings

::: details Screenshot
![workflow optimization settings screenshot](/workflow-optimizations.png)
:::

### Auto-search note title

Whether or not to automatically use the active notes title when searching for articles. The current selection will be prioritized.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"GitHub Sponsor": "https://github.com/sponsors/StrangeGirlMurph"
},
"isDesktopOnly": false
}
}
8 changes: 7 additions & 1 deletion src/commands/createArticleNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ async function createArticleNote(
}

const result = await generateInsert(settings, article, templateString, "");
const filePath = await createNoteInFolder(app, article.title, result.insert, folderPath, settings.overrideFiles);
const filePath = await createNoteInFolder(
app,
article.title,
result.insert,
folderPath,
settings.overrideFiles
);
if (!filePath) return;
if (settings.openCreatedNotes) {
app.workspace
Expand Down
45 changes: 27 additions & 18 deletions src/commands/linkArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async function linkArticle(
article: Article,
template: Template
) {
let templateString = template.templateString
const selection = editor.getSelection()
let templateString = template.templateString;
const selection = editor.getSelection();

if (template.createNote) {
if (template.useTemplateFile) {
Expand All @@ -42,7 +42,7 @@ async function linkArticle(
templateString = await app.vault.read(templateFile);
}

const content = await generateInsert(settings, article, templateString, selection)
const content = await generateInsert(settings, article, templateString, selection);

let folderPath: string | null =
template.customPath === "" ? settings.defaultNotePath : template.customPath;
Expand All @@ -56,28 +56,37 @@ async function linkArticle(
}
}

const notePath = await createNoteInFolder(app, article.title, content.insert, folderPath, settings.overrideFiles);
const notePath = await createNoteInFolder(
app,
article.title,
content.insert,
folderPath,
settings.overrideFiles
);
if (notePath == null) return;

editor.replaceSelection(`[[${notePath}|${
settings.prioritizeArticleTitle || selection === "" ? article.title : selection
}]]`);
editor.replaceSelection(
`[[${notePath}|${settings.prioritizeArticleTitle || selection === "" ? article.title : selection}]]`
);
} else {
const internalCursorMarker = "{cursorMarker}"
const internalCursorMarker = "{cursorMarker}";

let content = editor.getValue();
content = content.substring(0, editor.posToOffset(editor.getCursor("from"))) + templateString + internalCursorMarker + content.substring(editor.posToOffset(editor.getCursor("to")))
content =
content.substring(0, editor.posToOffset(editor.getCursor("from"))) +
templateString +
internalCursorMarker +
content.substring(editor.posToOffset(editor.getCursor("to")));

const result = await generateInsert(settings, article, content, selection);
let newContent = result.insert
let cursorPosition = result.cursorPosition
if (cursorPosition == null)
cursorPosition = newContent.search(internalCursorMarker);
newContent = newContent.replace(internalCursorMarker, "")
let newContent = result.insert;
let cursorPosition = result.cursorPosition;
if (cursorPosition == null) cursorPosition = newContent.search(internalCursorMarker);
newContent = newContent.replace(internalCursorMarker, "");

editor.setValue(newContent)
const cursorPos = editor.offsetToPos(cursorPosition!)
editor.setCursor(cursorPos)
editor.scrollIntoView({from: cursorPos, to: cursorPos}, true);
editor.setValue(newContent);
const cursorPos = editor.offsetToPos(cursorPosition!);
editor.setCursor(cursorPos);
editor.scrollIntoView({ from: cursorPos, to: cursorPos }, true);
}
}
10 changes: 5 additions & 5 deletions src/utils/generateInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function generateInsert(
article: Article,
content: string,
selection: string
): Promise<{insert: string, cursorPosition: number | null}> {
): Promise<{ insert: string; cursorPosition: number | null }> {
const title = settings.prioritizeArticleTitle || selection === "" ? article.title : selection;
let insert = content
.replaceAll("{title}", title)
Expand Down Expand Up @@ -44,10 +44,10 @@ export async function generateInsert(
if (content.includes("{description}") && !article.description)
new Notice("The article has no description.");

let cursorPosition: number | null = insert.search("{cursor}")
cursorPosition = cursorPosition != -1 ? cursorPosition : null
let cursorPosition: number | null = insert.search("{cursor}");
cursorPosition = cursorPosition != -1 ? cursorPosition : null;

insert = insert.replaceAll("{cursor}", "")
insert = insert.replaceAll("{cursor}", "");

return {insert, cursorPosition };
return { insert, cursorPosition };
}
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"2.4.3": "0.15.0",
"2.4.4": "0.15.0",
"2.5.0": "0.15.0"
}
}

0 comments on commit e2e2d5b

Please sign in to comment.