From a7c2a934b70150c71c8fbcdf3df43c731c95440d Mon Sep 17 00:00:00 2001 From: Asone Date: Mon, 10 Apr 2023 11:50:11 +0200 Subject: [PATCH] feat(template): slight improvements on examples --- .env.test | 2 +- README.md | 1 + src/fixtures/default.template | 4 ++-- src/fixtures/rss.json | 6 ++++-- src/fixtures/rss.yaml | 2 ++ src/template/template.rs | 10 +++++----- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.env.test b/.env.test index 1324916..d75059b 100644 --- a/.env.test +++ b/.env.test @@ -13,4 +13,4 @@ NOSTR_BANNER="https://example.com/banner.png" NOSTR_DESCRIPTION="Craig Wright is not satoshi" NOSTR_PICTURE="https://example.com/picture.jpg" -DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl:{url}\nTags:{tags}" \ No newline at end of file +DEFAULT_TEMPLATE="test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}" \ No newline at end of file diff --git a/README.md b/README.md index e1974ab..5aa39cc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Below are the variables you can use for templating : | Variable | Description | | ------------ |---------------------------------- | | name | The `feed` given name | +| title | The `entry` title | | content | The `entry` content. Usually a description of the item | | url | The URL to the `entry` | | tags | The tags of the `feed` | diff --git a/src/fixtures/default.template b/src/fixtures/default.template index c594962..368c3d9 100644 --- a/src/fixtures/default.template +++ b/src/fixtures/default.template @@ -1,4 +1,4 @@ Default nostrss template file Feed: {name} -Url:{url} -Tags:{tags} \ No newline at end of file +Url: {url} +Tags: {tags} \ No newline at end of file diff --git a/src/fixtures/rss.json b/src/fixtures/rss.json index 9104678..010238f 100644 --- a/src/fixtures/rss.json +++ b/src/fixtures/rss.json @@ -9,7 +9,8 @@ "id": "bitcoin-reddit", "name": "reddit r/bitcoin", "url": "https://www.reddit.com/r/bitcoin/.rss", - "schedule": "1/5 * * * * * *" + "schedule": "1/5 * * * * * *", + "template": "./src/fixtures/default.template" }, { "id": "nostr-reddit", @@ -18,6 +19,7 @@ "schedule": "1/10 * * * * * *", "profiles": [ "reddit" - ] + ], + "template": null } ] \ No newline at end of file diff --git a/src/fixtures/rss.yaml b/src/fixtures/rss.yaml index c9576c0..75a0d82 100644 --- a/src/fixtures/rss.yaml +++ b/src/fixtures/rss.yaml @@ -5,10 +5,12 @@ schedule: "1/5 * * * * * *" tags: ["wikipedia","changes"] profiles: null + template: "./src/fixtures/default.template" - id: "stackernews" name: "Stacker news feed" url: "https://stacker.news/rss" schedule: "1/30 * * * * * *" + template: null - id: "bitcoin-reddit" name: "r/bitcoin reddit feed" url: "https://www.reddit.com/r/bitcoin/.rss" diff --git a/src/template/template.rs b/src/template/template.rs index 8a50fe5..ce17e7c 100644 --- a/src/template/template.rs +++ b/src/template/template.rs @@ -57,7 +57,7 @@ impl TemplateProcessor { tags_string = format!("{} #{}", tags_string, tag); } - map.insert("tags", tags_string); + map.insert("tags", tags_string.trim().to_string()); let templ = Template::new(&template); @@ -128,7 +128,7 @@ mod tests { assert_eq!(result.is_ok(), true); let expected = - "test nostrss template\nFeed: Generic feed\nUrl:https://www.nostr.info\nTags:" + "test nostrss template\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: " .to_string(); let result = result.unwrap(); @@ -173,7 +173,7 @@ mod tests { assert_eq!(result.is_ok(), true); let result = result.unwrap(); - let expected = "Default nostrss template file\nFeed: Generic feed\nUrl:https://www.nostr.info\nTags: #Test #nostrss".to_string(); + let expected = "Default nostrss template file\nFeed: Generic feed\nUrl: https://www.nostr.info\nTags: #Test #nostrss".to_string(); assert_eq!(result, expected); } @@ -217,7 +217,7 @@ mod tests { let result = result.unwrap(); let expected = - "Default nostrss template file\nFeed: {name}\nUrl:{url}\nTags:{tags}".to_string(); + "Default nostrss template file\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string(); assert_eq!(result, expected); let bad_path = "./src/fixture/nonexistant.template".to_string(); @@ -229,7 +229,7 @@ mod tests { assert_eq!(result.is_ok(), true); let result = result.unwrap(); - let expected = "test nostrss template\nFeed: {name}\nUrl:{url}\nTags:{tags}".to_string(); + let expected = "test nostrss template\nFeed: {name}\nUrl: {url}\nTags: {tags}".to_string(); assert_eq!(result, expected); } }