File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -18,12 +18,11 @@ export const DEFAULT_SETTINGS: HackerNewsSettings = {
1818 storiesFolder : "HackerNews" ,
1919 storyTemplate : `---
2020date: {{date}}
21- source: [ {{url}}]({{url}})
21+ source: {{url}}
2222
2323---
2424
2525# {{title}}
26- ---
2726
2827> notes from [{{title}}]({{url}})
2928`
Original file line number Diff line number Diff line change 11import { Notice } from 'obsidian' ;
22import path from 'path' ;
3+ import moment from 'moment' ;
34import 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}
You can’t perform that action at this time.
0 commit comments