Skip to content

Commit 9758bd5

Browse files
committed
template in action.
1 parent f42deca commit 9758bd5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/_constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ export const DEFAULT_SETTINGS: HackerNewsSettings = {
1818
storiesFolder: "HackerNews",
1919
storyTemplate: `---
2020
date: {{date}}
21-
source: [{{url}}]({{url}})
21+
source: {{url}}
2222
2323
---
2424
2525
# {{title}}
26-
---
2726
2827
> notes from [{{title}}]({{url}})
2928
`

src/apiManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Notice } from 'obsidian';
22
import path from 'path';
3+
import moment from 'moment';
34
import type {
45
HNItem,
56
} from "src/integrations/types";
@@ -41,8 +42,15 @@ export default class APIManager {
4142

4243
stat = await this.plugin.app.vault.adapter.stat(filePath)
4344
if (!stat) {
44-
await this.plugin.app.vault.create(filePath, `[${hnItem.title}](${hnItem.url})`)
45+
await this.plugin.app.vault.create(filePath, this.getStoryFileContent(hnItem))
4546
new Notice(`Story saved: ${hnItem.title}`)
4647
}
4748
}
49+
50+
getStoryFileContent(hnItem: HNItem): string {
51+
let data = this.plugin.settings.storyTemplate;
52+
return data.replace(/{{title}}/g, hnItem.title)
53+
.replace(/{{url}}/g, hnItem.url)
54+
.replace(/{{date}}/g, moment().format('LLLL'))
55+
}
4856
}

0 commit comments

Comments
 (0)