Skip to content

Commit

Permalink
Updated blog feed and metadata build scripts to
Browse files Browse the repository at this point in the history
use ES6 modules and Github Actions.
  • Loading branch information
chriscarrollsmith committed Oct 2, 2023
1 parent 0b274af commit 57331a1
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 419 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
echo "feedUrl=$feedUrl" >> $GITHUB_ENV
- name: Fetch RSS Feed
uses: Promptly-Technologies-LLC/rss-fetch-action@v1
uses: Promptly-Technologies-LLC/rss-fetch-action@v2
with:
feed_url: ${{ env.feedUrl }}
file_path: 'src/components/ui/RssFeed.json'
remove_last_build_date: true
feed_url: https://knowledgeworkersguide.substack.com/feed
file_path: ./src/components/ui/RssFeed.json
parser_options: "{\"useISODateFormat\": false, \"getExtraEntryFields\": \"(feedEntry) => { return { 'content:encoded': feedEntry['content:encoded'] || '' }; }\"}"

- name: Build
run: npm run build
Expand Down
133 changes: 87 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "promptlytechnologiesllc",
"version": "0.1.2",
"version": "0.2.0",
"author": "Christopher C. Smith",
"homepage": "https://promptlytechnologies.com",
"scripts": {
"dev": "vite",
"setmetadata": "node scripts/setmetadata.js",
"fetchblogfeed": "node scripts/fetchblogfeed.js",
"setmetadata": "node scripts/setmetadata.mjs",
"fetchblogfeed": "node scripts/fetchblogfeed.mjs",
"build": "npm run setmetadata && tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
Expand All @@ -20,15 +20,14 @@
"flowbite-react": "^0.4.10",
"fs": "^0.0.1-security",
"gh-pages": "^5.0.0",
"isomorphic-fetch": "^3.0.0",
"react": "^18.2.0",
"react-calendly": "^4.1.1",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1",
"react-router-hash-link": "^2.4.3",
"xml2js": "^0.6.0"
"react-router-hash-link": "^2.4.3"
},
"devDependencies": {
"@extractus/feed-extractor": "^7.0.6",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^5.61.0",
Expand Down
37 changes: 0 additions & 37 deletions scripts/fetchblogfeed.js

This file was deleted.

33 changes: 33 additions & 0 deletions scripts/fetchblogfeed.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'fs';
import { extract } from '@extractus/feed-extractor'

// Read JSON file
const sitedata = JSON.parse(fs.readFileSync('src/customizations/siteproperties.json', 'utf8'));
const feedUrl = sitedata.substackUrl + '/feed';

// Fetch the RSS feed
async function fetchRssFeed() {
try {
// Fetch the RSS feed
const feedData = await extract(feedUrl, {
useISODateFormat: false,
getExtraEntryFields: (feedEntry) => {
return { 'content:encoded': feedEntry['content:encoded'] || '' };
}
});

// Verify that the fetched data is a valid Javascript object
if (!feedData || typeof feedData !== 'object') {
throw new Error('Invalid RSS feed data');
}

// Convert the Javascript object to JSON and save as a UI component
fs.writeFileSync('src/components/ui/RssFeed.json', JSON.stringify(feedData, null, 2));

console.log('RSS feed saved successfully!');
} catch (error) {
console.error('Error fetching RSS feed:', error);
}
}

fetchRssFeed();
12 changes: 6 additions & 6 deletions scripts/setmetadata.js → scripts/setmetadata.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const cheerio = require('cheerio');
const beautify = require('js-beautify').html;
const URL = require('url').URL;
import fs from 'fs';
import * as cheerio from 'cheerio';
import { URL } from 'url';
import * as beautify from 'js-beautify';

// Read JSON file
const data = JSON.parse(fs.readFileSync('src/customizations/siteproperties.json', 'utf8'));
Expand Down Expand Up @@ -42,7 +42,7 @@ for (let card of data["socialCards"]) {
}

// Save updated HTML file
fs.writeFileSync('index.html', beautify($.html(), { indent_size: 2, preserve_newlines: false }));
fs.writeFileSync('index.html', beautify.default.html($.html(), { indent_size: 2, preserve_newlines: false }));

// Load package.json
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
Expand All @@ -63,4 +63,4 @@ if (url.hostname.endsWith('.github.io')) {
}

// Save package.json
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
Loading

0 comments on commit 57331a1

Please sign in to comment.