Skip to content

Commit

Permalink
+ filtered folders(closes #12)
Browse files Browse the repository at this point in the history
+ Tagging(closes #9)
+ customizable date format(closes #20)
+ template variables for filename, created date, description(closes #19)
+ making button row sticky in modal(closes #21)
+ visual identifier for articles where a note has been created(closes #11)
~ fixes bad check for read articles(closes #18)
  • Loading branch information
joethei committed Nov 18, 2021
1 parent 567a2fe commit e964b84
Show file tree
Hide file tree
Showing 21 changed files with 995 additions and 370 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,45 @@ Plugin for [Obsidian](https://obsidian.md)
![GitHub](https://img.shields.io/github/license/joethei/obsidian-rss)
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
---
![](https://i.joethei.space/obsidian-rss.png)

![Demo GIF](https://i.joethei.space/QQATWu36eC.gif)

## Features
- Reading RSS feeds from within obsidian
- Sorting feeds into folders(sorting into nested folders is on the roadmap [#3](https://github.com/joethei/obsidian-rss/issues/3))
- staring articles
- creating new notes from articles
- pasting article into current note
- creating custom filters
- tagging articles

![Demo GIF](https://i.joethei.space/QQATWu36eC.gif)

## Finding the RSS feed for a website

- Search for the RSS logo or a link on the website
- Use an browser addon ([Firefox](https://addons.mozilla.org/en-US/firefox/addon/awesome-rss/), [Chrome based](https://chrome.google.com/webstore/detail/get-rss-feed-url/kfghpdldaipanmkhfpdcjglncmilendn?hl=de))
- Search the websites sourcecode for `rss`

## Styling
If you want to style the plugin differently you can use the following css classes

- rss-read
- rss-not-read
- rss-filters
- rss-folders
- rss-folder
- rss-feed
- rss-feed-title
- rss-feed-items
- rss-feed-item
- rss-tag
- rss-tooltip
- rss-title
- rss-subtitle
- rss-content

For help with styling you can also check out the `#appearance` channel on the [Obsidian Members Group Discord](https://obsidian.md/community)

### Installing the plugin
- using the build in Community plugins(once this plugin is accepted)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "rss-reader",
"name": "RSS Reader",
"version": "0.5.0",
"version": "0.6.0",
"minAppVersion": "0.9.12",
"description": "Read RSS Feeds from within obsidian",
"author": "Johannes Theiner",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rss-reader",
"version": "0.5.0",
"version": "0.6.0",
"description": "Read RSS Feeds from inside obsidian",
"main": "main.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"eslint": "^7.32.0",
"lodash.groupby": "^4.6.0",
"obsidian": "^0.12.0",
"obsidian-community-lib": "0.0.17",
"obsidian-community-lib": "1.2.0",
"rollup": "^2.32.1",
"rollup-plugin-svelte": "^7.1.0",
"svelte": "^3.43.1",
Expand Down
1 change: 0 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ export default {
dedupe: ["svelte"],
}),
commonjs(),

]
};
50 changes: 50 additions & 0 deletions src/actions/Action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {RssFeedItem} from "../parser/rssParser";
import {createNewNote, openInBrowser, pasteToNote} from "../functions";
import RssReaderPlugin from "../main";
import {htmlToMarkdown} from "obsidian";
import {copy} from "obsidian-community-lib";
import {TagModal} from "../modals/TagModal";

export default class Action {

static CREATE_NOTE = new Action("create new note", "create-new", (plugin, item) : Promise<void> => {
return createNewNote(plugin, item);
});

static PASTE = new Action("paste to current note", "paste", (plugin, item) : Promise<void> => {
return pasteToNote(plugin, item);
});
static COPY = new Action("copy to clipboard", "feather-clipboard", ((plugin, item) : Promise<void> => {
return copy(htmlToMarkdown(item.content));
}));
static OPEN = new Action("open in browser", "open-elsewhere-glyph", ((plugin, item) : Promise<void> => {
openInBrowser(item);
return Promise.resolve();
}));
static TAGS = new Action("edit tags", "tag-glyph", (((plugin, item) => {
const modal = new TagModal(plugin, item.tags);

modal.onClose = async () => {
item.tags = modal.tags;
const items = plugin.settings.items;
await plugin.writeFeedContent(() => {
return items;
});
};

modal.open();
return Promise.resolve();
})));

static actions = Array.of(Action.TAGS, Action.CREATE_NOTE, Action.PASTE, Action.COPY, Action.OPEN);

readonly name: string;
readonly icon: string;
readonly processor: (plugin: RssReaderPlugin, value: RssFeedItem) => Promise<void>;

constructor(name: string, icon: string, processor: (plugin: RssReaderPlugin, item: RssFeedItem) => Promise<void>) {
this.name = name;
this.icon = icon;
this.processor = processor;
}
}
61 changes: 49 additions & 12 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {TextInputPrompt} from "./modals/TextInputPrompt";
import {FILE_NAME_REGEX} from "./consts";
import {isInVault} from "obsidian-community-lib";
import RssReaderPlugin from "./main";
import {RssReaderSettings} from "./settings/settings";

export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem) : Promise<void> {
const activeFile = plugin.app.workspace.getActiveFile();
Expand All @@ -14,16 +15,6 @@ export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem)
}
//make sure there are no slashes in the title.
const title = item.title.replace(/[\/\\:]/g, ' ');
const content = htmlToMarkdown(item.content);

const appliedTemplate = plugin.settings.template
.replace("{{title}}", item.title)
.replace("{{link}}", item.link)
.replace("{{author}}", item.creator)
.replace("{{published}}", item.pubDate)
.replace("{{folder}}", item.folder)
.replace("{{feed}}", item.feed)
.replace("{{content}}", content);

const inputPrompt = new TextInputPrompt(plugin.app, "Please specify a file name", "cannot contain: * \" \\ / < > : | ?", title, title);

Expand All @@ -42,11 +33,20 @@ export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem)
}
inputPrompt.close();

const appliedTemplate = applyTemplate(item, plugin.settings.template, plugin.settings, value);

const file = await plugin.app.vault.create(filePath, appliedTemplate);

await plugin.app.workspace.activeLeaf.openFile(file, {
state: {mode: 'edit'},
})
});

item.created = true;
const items = plugin.settings.items;
await plugin.writeFeedContent(() => {
return items;
});

new Notice("Created note from article");
});
}
Expand All @@ -60,14 +60,51 @@ export async function pasteToNote(plugin: RssReaderPlugin, item: RssFeedItem) :

const view = plugin.app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
const appliedTemplate = applyTemplate(item, plugin.settings.pasteTemplate, plugin.settings);

const editor = view.editor;
editor.replaceRange(htmlToMarkdown(item.content), editor.getCursor());
editor.replaceRange(htmlToMarkdown(appliedTemplate), editor.getCursor());

item.created = true;
const items = plugin.settings.items;
await plugin.writeFeedContent(() => {
return items;
});

new Notice("inserted article into note");
}
}

function applyTemplate(item: RssFeedItem, template: string, settings: RssReaderSettings, filename?: string) : string {
const content = htmlToMarkdown(item.content);

let result = replaceAll(template, "{{title}}", item.title);
result = replaceAll(result, "{{link}}", item.link);
result = replaceAll(result, "{{author}}", item.creator);
result = replaceAll(result, "{{content}}", content);
result = replaceAll(result, "{{published}}", window.moment(item.pubDate).format(settings.dateFormat));
result = replaceAll(result, "{{feed}}", item.feed);
result = replaceAll(result, "{{folder}}", item.folder);
result = replaceAll(result, "{{description}}", item.description);
if(filename) {
result = replaceAll(result, "{{filename}}", filename);
result = replaceAll(result, "{{created}}", window.moment().format(settings.dateFormat));
}

return result;
}

export function openInBrowser(item: RssFeedItem) : void {
if (typeof item.link === "string") {
window.open(item.link, '_blank');
}
}

//taken from: https://stackoverflow.com/a/1144788/5589264
function escapeRegExp(string: string) : string {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

function replaceAll(str: string, find: string, replace: string) : string {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
Loading

0 comments on commit e964b84

Please sign in to comment.