Skip to content

Add atom feed #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 348 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"scripts": {
"docusaurus": "docusaurus",
"prestart": "node scripts/resize-images.js && node scripts/generate-rss-feed.js",
"prebuild": "node scripts/resize-images.js && node scripts/generate-rss-feed.js",
"prestart": "node scripts/resize-images.js && node scripts/generate-rss-feed.js && node scripts/generate-atom-feed.js ",
"prebuild": "node scripts/resize-images.js && node scripts/generate-rss-feed.js && node scripts/generate-atom-feed.js",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
Expand All @@ -36,6 +36,7 @@
"canvas": "^2.11.2",
"clsx": "^2.0.0",
"curl": "^0.1.4",
"feed": "^5.1.0",
"fs": "^0.0.1-security",
"image-size": "^1.2.1",
"jimp": "^0.22.12",
Expand Down Expand Up @@ -80,5 +81,6 @@
},
"engines": {
"node": "18.x"
}
},
"type": "module"
}
70 changes: 70 additions & 0 deletions scripts/generate-atom-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import fs from 'fs';
import { Feed } from 'feed';
import { blogpostsDetails } from '../src/components/blog/blogpostsDetails.js';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const outputDir = path.join(__dirname, '../static');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

const generateAtomFeedFromBlogDetails = (feed, blogpostsDetails, nbOfBlogPosts) => {
let posts = [];
for (let i = 0; i < nbOfBlogPosts; i++) {
const post = blogpostsDetails[i];
posts.push({
title: post.title,
link: post.url,
description: post.summary,
date: new Date(post.date),
authors: post.authors.split(','),
})
};

posts.forEach((post) => {
feed.addItem({
title: post.title,
id: post.url,
link: post.url,
description: post.summary,
date: new Date(post.date),
author: [{ name: post.authors }],
});

})
return feed;
}
const AtomFeedLast20 = new Feed({
title: 'Recent blog posts featured by QuantStack team',
description: 'Atom feed for QuantStack website blog page',
id: 'https://quantstack.net/',
link: 'https://quantstack.net/',
language: 'en',
updated: new Date(),
feedLinks: {
atom: 'https://quantstack.net/atom.xml',
},
author: {
name: 'QuantStack Team',
link: 'https://quantstack.net',
},
});


const updatedFeedLast20 = generateAtomFeedFromBlogDetails(AtomFeedLast20, blogpostsDetails, 20);
const xml = updatedFeedLast20.atom1(); // Atom format
fs.writeFileSync(path.join(outputDir, 'atom.xml'), xml);

/*const AtomFeedAll = new Feed({
title: 'All blog posts featured by QuantStack team',
description: 'Atom feed for QuantStack website blog page',
feed_url: 'https://quantstack.net/atom_all.xml',
site_url: 'https://quantstack.net',
language: 'en',
});

const updatedFeedAll = generateAtomFeedFromBlogDetails(AtomFeedAll, blogpostsDetails, blogpostsDetails.length)
fs.writeFileSync(path.join(outputDir, 'atom_all.xml'), updatedFeedAll.atom1({ indent: true }));*/
11 changes: 7 additions & 4 deletions scripts/generate-rss-feed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const fs = require('fs');
const RSS = require('rss');
const { blogpostsDetails } = require('../src/components/blog/blogpostsDetails.js');
const path = require('path');
import fs from 'fs';
import RSS from 'rss';
import { blogpostsDetails } from '../src/components/blog/blogpostsDetails.js';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const outputDir = path.join(__dirname, '../static');
if (!fs.existsSync(outputDir)) {
Expand Down
15 changes: 9 additions & 6 deletions scripts/resize-images.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
const sizeOf = require('image-size');
const fullSizeDir = path.join(__dirname, '../static', 'img', 'blogposts', 'full-size-images');
const reducedSizeDir = path.join(__dirname, '../static', 'img', 'blogposts', 'resized-images');
import sharp from 'sharp';
import fs from 'fs';
import path from 'path';
import sizeOf from 'image-size';
import { fileURLToPath } from 'url';
const containerHeight = 180;
const containerWidth = 273;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const fullSizeDir = path.join(__dirname, '../static', 'img', 'blogposts', 'full-size-images');
const reducedSizeDir = path.join(__dirname, '../static', 'img', 'blogposts', 'resized-images');

if (!fs.existsSync(reducedSizeDir)) {
fs.mkdirSync(reducedSizeDir, { recursive: true });
Expand Down
Loading
Loading