Skip to content

Commit

Permalink
feat: cloudinary
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Aug 28, 2023
1 parent 8f86aa7 commit fa13ff1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion blog-website/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ts-check
const docusaurusCloudinaryRehypePlugin = require('rehype-cloudinary-docusaurus');

const USE_CLOUDINARY = false; // process.env['USE_CLOUDINARY'] === 'true';
const USE_CLOUDINARY = process.env['USE_CLOUDINARY'] === 'true';
console.log('USE_CLOUDINARY', USE_CLOUDINARY);

const fontaine = require('fontaine');
Expand Down
25 changes: 12 additions & 13 deletions trim-xml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { SitemapUrl, Sitemap, AtomFeed, RssItem, RssFeed } from './types';
const rootUrl = 'https://johnnyreilly.com';

async function enrichUrlsWithLastmodAndFilterCanonicals(
filteredUrls: SitemapUrl[]
filteredUrls: SitemapUrl[],
): Promise<SitemapUrl[]> {
const urls: SitemapUrl[] = [];
let blogFilePath: string | undefined;
Expand Down Expand Up @@ -51,10 +51,10 @@ async function patchOpenGraphImageToCloudinary() {
.filter((dir) =>
fs
.statSync(path.resolve('..', 'blog-website', 'build', dir))
.isDirectory()
.isDirectory(),
)
.map((dir) =>
path.resolve('..', 'blog-website', 'build', dir, 'index.html')
path.resolve('..', 'blog-website', 'build', dir, 'index.html'),
)
.filter((file) => fs.existsSync(file));

Expand All @@ -77,7 +77,7 @@ async function patchOpenGraphImageToCloudinary() {
})
.replace(ogImageRegex, function (_match, url) {
return `<meta data-rh="true" property="og:image" content="https://res.cloudinary.com/priou/image/fetch/f_auto,q_auto,w_auto,dpr_auto/${url}">`;
})
}),
);
}
}
Expand All @@ -87,7 +87,7 @@ async function trimSitemapXML() {
'..',
'blog-website',
'build',
'sitemap.xml'
'sitemap.xml',
);

console.log(`Loading ${sitemapPath}`);
Expand All @@ -102,16 +102,15 @@ async function trimSitemapXML() {
(url) =>
// url.loc !== `${rootUrl}/tags` &&
// !url.loc.startsWith(rootUrl + '/tags/') &&
!url.loc.startsWith(rootUrl + '/page/')
!url.loc.startsWith(rootUrl + '/page/'),
);

console.log(
`Reducing ${sitemap.urlset.url.length} urls to ${filteredUrls.length} urls`
`Reducing ${sitemap.urlset.url.length} urls to ${filteredUrls.length} urls`,
);

sitemap.urlset.url = await enrichUrlsWithLastmodAndFilterCanonicals(
filteredUrls
);
sitemap.urlset.url =
await enrichUrlsWithLastmodAndFilterCanonicals(filteredUrls);

const builder = new XMLBuilder({ format: false, ignoreAttributes: false });
const shorterSitemapXml = builder.build(sitemap);
Expand Down Expand Up @@ -149,7 +148,7 @@ async function trimAtomXML() {
}

console.log(
`Reducing ${rss.feed.entry.length} entries to ${top20Entries.length} entries`
`Reducing ${rss.feed.entry.length} entries to ${top20Entries.length} entries`,
);

rss.feed.entry = top20Entries;
Expand Down Expand Up @@ -194,7 +193,7 @@ async function trimRssXML() {
}

console.log(
`Reducing ${rss.rss.channel.item.length} entries to ${top20Entries.length} entries`
`Reducing ${rss.rss.channel.item.length} entries to ${top20Entries.length} entries`,
);

rss.rss.channel.item = top20Entries;
Expand All @@ -213,7 +212,7 @@ async function trimRssXML() {
async function main() {
const startedAt = new Date();

// await patchOpenGraphImageToCloudinary();
await patchOpenGraphImageToCloudinary();
await trimSitemapXML();
// now handled by createFeedItems
// await trimAtomXML();
Expand Down

0 comments on commit fa13ff1

Please sign in to comment.