Skip to content

Commit 47ffbaf

Browse files
committed
Bump versions, add license
1 parent ff31dfa commit 47ffbaf

File tree

5 files changed

+61
-25
lines changed

5 files changed

+61
-25
lines changed

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright 2021 Jonathan Miller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
## Obsidian Wikipedia
1+
# Obsidian Wikipedia
22

33
This is a plugin for Obsidian (https://obsidian.md).
44

5-
This plugin gets the first section of Wikipedia for the active note's title or for
6-
a search term and pastes it in.
5+
This plugin gets the first section of Wikipedia and pastes it into your active note.
6+
7+
## Usage
8+
9+
This plugin has two commands:
10+
11+
- `Get Wikipedia for Active Note`, which gets the first section of Wikipedia using the active note's title as search term.
12+
- `Get Wikipedia for Search Term`, which gets the first section of Wikipedia for a search term.
13+
14+
## Settings
15+
16+
Settings for this plugin include:
17+
18+
- **Language Prefix**: The prefix before `wikipedia.org` used to access the language of Wikipedia you want. (Default: 'en')
19+
- **Extract Template**: The template to use to paste your extract. Available variables are {{text}}, {{searchTerm}}, and {{url}}
20+
- **Bold Search Term?**: If set to True, bolds the first instance of the search term in the extract
21+
- **Use Paragraph Template?**: If set to true, the paragraph template will be inserted for each paragraph of text for {{text}} in main template.
22+
- **Paragraph Template**: If *Use Paragraph Template* is set to true, this template will be inserted for each paragraph in the text extract. Available variable: {{paragraphText}}.

main.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ interface WikiExtract {
1919
interface MyPluginSettings {
2020
template: string;
2121
shouldUseParagraphTemplate: boolean;
22-
shouldBoldTitle: boolean;
22+
shouldBoldSearchTerm: boolean;
2323
paragraphTemplate: string;
2424
language: string;
2525
}
2626

2727
const DEFAULT_SETTINGS: MyPluginSettings = {
2828
template: `{{text}}\n> [Wikipedia]({{url}})`,
2929
shouldUseParagraphTemplate: true,
30-
shouldBoldTitle: true,
30+
shouldBoldSearchTerm: true,
3131
paragraphTemplate: `> {{paragraphText}}\n>\n`,
3232
language: "en",
3333
};
@@ -39,14 +39,18 @@ const disambiguationIdentifier = "may refer to:";
3939
export default class MyPlugin extends Plugin {
4040
settings: MyPluginSettings;
4141

42+
getLanguage(): string {
43+
return this.settings.language ? this.settings.language : "en";
44+
}
45+
4246
getUrl(title: string): string {
43-
return `https://${this.settings.language}.wikipedia.org/wiki/${encodeURI(
47+
return `https://${this.getLanguage()}.wikipedia.org/wiki/${encodeURI(
4448
title
4549
)}`;
4650
}
4751

4852
getApiUrl(): string {
49-
return `https://${this.settings.language}.` + extractApiUrl;
53+
return `https://${this.getLanguage()}.` + extractApiUrl;
5054
}
5155

5256
formatExtractText(extract: WikiExtract, searchTerm: string): string {
@@ -66,7 +70,7 @@ export default class MyPlugin extends Plugin {
6670
} else {
6771
formattedText = text.split("==")[0].trim();
6872
}
69-
if (this.settings.shouldBoldTitle) {
73+
if (this.settings.shouldBoldSearchTerm) {
7074
const pattern = new RegExp(searchTerm, "i");
7175
formattedText = formattedText.replace(pattern, `**${searchTerm}**`);
7276
}
@@ -120,7 +124,12 @@ export default class MyPlugin extends Plugin {
120124
const url = this.getApiUrl() + encodeURIComponent(title);
121125
const json = await fetch(url)
122126
.then((response) => response.json())
123-
.catch(() => new Notice('Failed to get Wikipedia. Check your internet connection or language prefix.'));
127+
.catch(
128+
() =>
129+
new Notice(
130+
"Failed to get Wikipedia. Check your internet connection or language prefix."
131+
)
132+
);
124133
const extract = this.parseResponse(json);
125134
return extract;
126135
}
@@ -260,7 +269,7 @@ class SampleSettingTab extends PluginSettingTab {
260269
containerEl.createEl("h2", { text: "Obsidian Wikipedia" });
261270

262271
new Setting(containerEl)
263-
.setName("Wikipedia Language")
272+
.setName("Wikipedia Language Prefix")
264273
.setDesc(`Choose Wikipedia language prefix to use (ex. en for English)`)
265274
.addText((textField) => {
266275
textField
@@ -288,15 +297,15 @@ class SampleSettingTab extends PluginSettingTab {
288297
);
289298

290299
new Setting(containerEl)
291-
.setName("Bold Title?")
300+
.setName("Bold Search Term?")
292301
.setDesc(
293-
"If set to true, the first instance of the page title will be **bolded**"
302+
"If set to true, the first instance of the search term will be **bolded**"
294303
)
295304
.addToggle((toggle) =>
296305
toggle
297-
.setValue(this.plugin.settings.shouldBoldTitle)
306+
.setValue(this.plugin.settings.shouldBoldSearchTerm)
298307
.onChange(async (value) => {
299-
this.plugin.settings.shouldBoldTitle = value;
308+
this.plugin.settings.shouldBoldSearchTerm = value;
300309
await this.plugin.saveSettings();
301310
})
302311
);

manifest.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"id": "obsidian-wikipedia",
3-
"name": "Wikipedia",
4-
"version": "0.1.0",
5-
"minAppVersion": "0.9.12",
6-
"description": "Grabs information from Wikipedia for a topic and brings it into Obsidian notes",
7-
"author": "Jonathan Miller",
8-
"authorUrl": "https://jmill.dev",
9-
"isDesktopOnly": false
2+
"id": "obsidian-wikipedia",
3+
"name": "Wikipedia",
4+
"version": "1.0.0",
5+
"minAppVersion": "0.9.12",
6+
"description": "Grabs information from Wikipedia for a topic and brings it into Obsidian notes",
7+
"author": "Jonathan Miller",
8+
"authorUrl": "https://jmill.dev",
9+
"isDesktopOnly": false
1010
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "obsidian-wikipedia",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"description": "Grabs information from Wikipedia for a topic and brings it into Obsidian notes",
55
"main": "main.js",
66
"scripts": {
77
"dev": "rollup --config rollup.config.js -w",
88
"build": "rollup --config rollup.config.js --environment BUILD:production"
99
},
10-
"keywords": [],
11-
"author": "",
10+
"keywords": [
11+
"obsidian-plugin"
12+
],
13+
"author": "Jonathan Miller",
1214
"license": "MIT",
1315
"devDependencies": {
1416
"@rollup/plugin-commonjs": "^18.0.0",

0 commit comments

Comments
 (0)