webring 0.0.2 → 1.0.0

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,19 @@ 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
- ## [Unreleased]
8
+ ## [1.0.0](https://github.com/shepherdjerred/webring/compare/v0.3.0...v1.0.0) (2024-06-03)
9
9
 
10
- * Initial release
10
+
11
+ ### ⚠ BREAKING CHANGES
12
+
13
+ * add link
14
+
15
+ ### Documentation
16
+
17
+ * add link ([1a5d327](https://github.com/shepherdjerred/webring/commit/1a5d327a002785809e84aab70b19d18dd135f78b))
18
+
19
+ ## [0.3.0](https://github.com/shepherdjerred/webring/compare/v0.2.0...v0.3.0) (2024-06-03)
20
+
21
+ ### Features
22
+
23
+ - allow filename to be configurable ([cc7bb5f](https://github.com/shepherdjerred/webring/commit/cc7bb5f3139f306952d03568fc63cc9fcbfaad5e))
package/README.md CHANGED
@@ -11,7 +11,7 @@ Inspired by:
11
11
 
12
12
  ## Installation
13
13
 
14
- ```
14
+ ```bash
15
15
  npm i webring
16
16
  ```
17
17
 
@@ -19,14 +19,37 @@ npm i webring
19
19
 
20
20
  This library is meant to be used with static site generators. It is framework agnostic.
21
21
 
22
- ### Astro
23
-
24
- ### Command Line
25
-
26
- You can use this library to generate static HTML which can be included into your site using it's include mechanisms
27
-
28
- ## Configuration
29
-
30
22
  ```typescript
31
-
23
+ import { type Configuration, run } from "webring";
24
+
25
+ // create a configuration object
26
+ const config: Configuration = {
27
+ sources: [
28
+ {
29
+ url: "https://drewdevault.com/blog/index.xml",
30
+ title: "Drew DeVault",
31
+ },
32
+ {
33
+ url: "https://danluu.com/atom.xml",
34
+ title: "Dan Luu",
35
+ },
36
+ {
37
+ url: "https://jakelazaroff.com/rss.xml",
38
+ title: "Jake Lazaroff",
39
+ },
40
+ ],
41
+ number: 3,
42
+ cache_duration_minutes: 60,
43
+ truncate: 300,
44
+ };
45
+
46
+ // run the application
47
+ const result = await run(config);
48
+
49
+ // do something with the results
50
+ result.map((entry) => {
51
+ console.log(entry);
52
+ });
32
53
  ```
54
+
55
+ I use this with Astro on my [personal website](https://github.com/shepherdjerred/sjer.red/blob/main/src/components/BlogWebring.astro#L17-L22).
package/dist/cache.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as R from "remeda";
2
+ import { fetch } from "./fetch.js";
2
3
  export async function runWithCache(config, cache) {
3
- const promises = R.pipe(config.sources, R.map((source) => fetchWithCache(source, cache, config)), R.filter((result) => result !== undefined));
4
+ const promises = R.pipe(config.sources, R.map((source) => fetchWithCache(source, cache, config)));
4
5
  const results = await Promise.all(promises);
5
6
  const definedResults = results.filter((result) => result !== undefined);
6
7
  const updatedCache = R.pipe(definedResults, R.map((result) => [result.source.url, { timestamp: new Date(), data: result }]), R.fromEntries());
package/dist/fetch.js CHANGED
@@ -17,7 +17,7 @@ export async function fetch(source, length) {
17
17
  url: firstItem.link,
18
18
  date: new Date(firstItem.date),
19
19
  source,
20
- preview: preview ? truncate(sanitizeHtml(preview), length) : undefined,
20
+ preview: preview ? truncate.default(sanitizeHtml(preview), length) : undefined,
21
21
  };
22
22
  }
23
23
  catch (e) {
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import { type Configuration, type Result } from "./types.js";
2
2
  export declare function run(config: Configuration): Promise<Result>;
3
+ export * from "./types.js";
4
+ export * from "./cache.js";
5
+ export * from "./fetch.js";
package/dist/index.js CHANGED
@@ -2,12 +2,10 @@ import { runWithCache } from "./cache.js";
2
2
  import { CacheSchema } from "./types.js";
3
3
  import fs from "fs/promises";
4
4
  export async function run(config) {
5
- const cacheFilename = "cache.json";
6
- const currentDir = process.cwd();
7
- const fullFilename = `${currentDir}/${cacheFilename}`;
5
+ const cacheFilename = config.cache_file;
8
6
  let cacheObject = {};
9
7
  try {
10
- const cacheFile = await fs.readFile(fullFilename);
8
+ const cacheFile = await fs.readFile(cacheFilename);
11
9
  cacheObject = CacheSchema.parse(JSON.parse(cacheFile.toString()));
12
10
  }
13
11
  catch (e) {
@@ -16,6 +14,9 @@ export async function run(config) {
16
14
  }
17
15
  const [result, updatedCache] = await runWithCache(config, cacheObject);
18
16
  // write the updated cache to cache.json
19
- await fs.writeFile(fullFilename, JSON.stringify(updatedCache));
17
+ await fs.writeFile(cacheFilename, JSON.stringify(updatedCache));
20
18
  return result;
21
19
  }
20
+ export * from "./types.js";
21
+ export * from "./cache.js";
22
+ export * from "./fetch.js";
package/dist/types.d.ts CHANGED
@@ -22,9 +22,10 @@ declare const ConfigurationSchema: z.ZodObject<{
22
22
  url: string;
23
23
  title: string;
24
24
  }>, "many">;
25
- number: z.ZodNumber;
26
- cache_duration_minutes: z.ZodNumber;
27
- truncate: z.ZodNumber;
25
+ number: z.ZodDefault<z.ZodNumber>;
26
+ cache_duration_minutes: z.ZodDefault<z.ZodNumber>;
27
+ truncate: z.ZodDefault<z.ZodNumber>;
28
+ cache_file: z.ZodDefault<z.ZodString>;
28
29
  }, "strip", z.ZodTypeAny, {
29
30
  number: number;
30
31
  sources: {
@@ -33,14 +34,16 @@ declare const ConfigurationSchema: z.ZodObject<{
33
34
  }[];
34
35
  cache_duration_minutes: number;
35
36
  truncate: number;
37
+ cache_file: string;
36
38
  }, {
37
- number: number;
38
39
  sources: {
39
40
  url: string;
40
41
  title: string;
41
42
  }[];
42
- cache_duration_minutes: number;
43
- truncate: number;
43
+ number?: number | undefined;
44
+ cache_duration_minutes?: number | undefined;
45
+ truncate?: number | undefined;
46
+ cache_file?: string | undefined;
44
47
  }>;
45
48
  export type ResultEntry = z.infer<typeof ResultEntrySchema>;
46
49
  declare const ResultEntrySchema: z.ZodObject<{
package/dist/types.js CHANGED
@@ -1,13 +1,20 @@
1
1
  import { z } from "zod";
2
2
  const SourceSchema = z.object({
3
+ // the url of the feed
3
4
  url: z.string(),
5
+ // a title for the feed
4
6
  title: z.string(),
5
7
  });
6
8
  const ConfigurationSchema = z.object({
9
+ // list of sources to fetch
7
10
  sources: SourceSchema.array(),
8
- number: z.number(),
9
- cache_duration_minutes: z.number(),
10
- truncate: z.number(),
11
+ // how many entries to return
12
+ number: z.number().default(3),
13
+ // how long to cache a results for
14
+ cache_duration_minutes: z.number().default(60),
15
+ // how many words to truncate the preview to
16
+ truncate: z.number().default(300),
17
+ cache_file: z.string().default("cache.json"),
11
18
  });
12
19
  const ResultEntrySchema = z.object({
13
20
  title: z.string(),
package/package.json CHANGED
@@ -1,41 +1,51 @@
1
1
  {
2
2
  "name": "webring",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "1.0.0",
5
5
  "scripts": {
6
- "lint": "eslint .",
6
+ "lint": "eslint src",
7
7
  "build": "tsc",
8
- "test": ""
8
+ "prepare": "husky"
9
9
  },
10
10
  "main": "dist/index.js",
11
11
  "types": "dist/index.d.ts",
12
12
  "dependencies": {
13
- "remeda": "^2.0.0",
13
+ "remeda": "^2.0.1",
14
14
  "rss-parser": "^3.13.0",
15
15
  "sanitize-html": "^2.13.0",
16
16
  "truncate-html": "^1.1.1",
17
17
  "zod": "^3.23.8"
18
18
  },
19
19
  "devDependencies": {
20
- "@eslint/js": "^9.3.0",
20
+ "@commitlint/cli": "^19.3.0",
21
+ "@commitlint/config-conventional": "^19.2.2",
22
+ "@eslint/js": "^9.4.0",
21
23
  "@tsconfig/node20": "^20.1.4",
22
24
  "@tsconfig/strictest": "^2.0.5",
23
25
  "@types/eslint__js": "^8.42.3",
24
- "@types/node": "^20.12.13",
26
+ "@types/node": "^20.14.0",
25
27
  "@types/sanitize-html": "^2.11.0",
26
28
  "@typescript-eslint/eslint-plugin": "^7.11.0",
27
29
  "@typescript-eslint/parser": "^7.11.0",
28
30
  "eslint": "^8.57.0",
29
31
  "husky": "^9.0.11",
30
32
  "lint-staged": "^15.2.5",
31
- "prettier": "^3.2.5",
33
+ "prettier": "^3.3.0",
32
34
  "typescript": "^5.4.5",
33
35
  "typescript-eslint": "^7.11.0"
34
36
  },
35
37
  "lint-staged": {
36
- "*.{js,jsx,ts,tsx}": "eslint --cache --fix",
38
+ "*.{ts,tsx}": "eslint --cache --fix",
37
39
  "*": "prettier --ignore-unknown --write"
38
40
  },
41
+ "commitlint": {
42
+ "extends": [
43
+ "@commitlint/config-conventional"
44
+ ]
45
+ },
46
+ "prettier": {
47
+ "printWidth": 120
48
+ },
39
49
  "files": [
40
50
  "dist",
41
51
  "package.json",