webring 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.3](https://github.com/shepherdjerred/webring/compare/v1.0.2...v1.0.3) (2024-06-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * create dir to cache ([a30645c](https://github.com/shepherdjerred/webring/commit/a30645c11d2afe91f7802c91b2c82eef9a97c717))
14
+
8
15
  ## [1.0.2](https://github.com/shepherdjerred/webring/compare/v1.0.1...v1.0.2) (2024-06-21)
9
16
 
10
17
 
package/README.md CHANGED
@@ -17,13 +17,13 @@ npm i webring
17
17
 
18
18
  ## Quick Start
19
19
 
20
- This library is meant to be used with static site generators. It is framework agnostic.
20
+ This library is meant to be used with static site generators. It is framework agnostic. I use this with [Astro](https://astro.build/) on my [personal website](https://github.com/shepherdjerred/sjer.red/blob/main/src/components/BlogWebring.astro#L17-L22).
21
21
 
22
22
  ```typescript
23
- import { type Configuration, run } from "webring";
23
+ import { run } from "webring";
24
+ import { type Configuration, type Result } from "webring";
24
25
 
25
- // create a configuration object
26
- const config: Configuration = {
26
+ export const config: Configuration = {
27
27
  sources: [
28
28
  {
29
29
  url: "https://drewdevault.com/blog/index.xml",
@@ -38,18 +38,39 @@ const config: Configuration = {
38
38
  title: "Jake Lazaroff",
39
39
  },
40
40
  ],
41
+ // the output will return the three most recent posts from the above sources
41
42
  number: 3,
42
- cache_duration_minutes: 60,
43
+ // the output will return santized HTML truncated to 300 characters
43
44
  truncate: 300,
45
+ // if this is defined, we'll cache the results
46
+ cache: {
47
+ // the file to use as a cache
48
+ cache_file: "webring.json",
49
+ // how long the cache should remain valid for
50
+ cache_duration_minutes: 60,
51
+ },
44
52
  };
45
53
 
46
- // run the application
47
- const result = await run(config);
54
+ // type Result = {
55
+ // title: string,
56
+ // url: string,
57
+ // date: Date,
58
+ // source: {
59
+ // url: string,
60
+ // title: string,
61
+ // },
62
+ // // this will be undefined if the RSS feed is empty
63
+ // preview?: string
64
+ // }[]
65
+ export const result: Result = await run(config);
48
66
 
49
- // do something with the results
50
67
  result.map((entry) => {
51
- console.log(entry);
68
+ // do something with the results
69
+ // for example, you might render each item as an HTML block
52
70
  });
53
71
  ```
54
72
 
55
- I use this with Astro on my [personal website](https://github.com/shepherdjerred/sjer.red/blob/main/src/components/BlogWebring.astro#L17-L22).
73
+ Here's what I do for my blog:
74
+
75
+ 1. Run `map` against the resulting array ([code](https://github.com/shepherdjerred/sjer.red/blob/f72b2b75bf0722ba8ff0fdd45f31c02c2ee5089d/src/components/BlogWebring.astro#L17-L22)).
76
+ 1. Render a component for each entry ([code](https://github.com/shepherdjerred/sjer.red/blob/f72b2b75bf0722ba8ff0fdd45f31c02c2ee5089d/src/components/WebringEntry.astro)).
package/dist/cache.js CHANGED
@@ -14,6 +14,7 @@ async function loadCache({ cache_file }) {
14
14
  }
15
15
  }
16
16
  async function saveCache({ cache_file }, cache) {
17
+ await fs.mkdir(cache_file.split("/").slice(0, -1).join("/"), { recursive: true });
17
18
  await fs.writeFile(cache_file, JSON.stringify(cache));
18
19
  }
19
20
  function toCacheEntry(result, now) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webring",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "scripts": {
6
6
  "prepare": "husky",
7
7
  "lint": "eslint src",