Skip to content
Closed
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
5 changes: 0 additions & 5 deletions next-sitemap.js

This file was deleted.

10 changes: 10 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@ module.exports = withBundleAnalyzer(
locales: ['en'],
defaultLocale: 'en',
},
rewrites: async () => [
{
source: '/rss.xml',
destination: '/api/rss.xml',
},
{
source: '/sitemap.xml',
destination: '/api/sitemap.xml',
},
],
})
);
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"license": "MIT",
"scripts": {
"analyze": "ANALYZE=true next build",
"build": "next build && next-sitemap",
"postbuild": "next-sitemap",
"build": "next build",
"dev": "NODE_OPTIONS='--inspect' next dev",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "next start",
Expand Down Expand Up @@ -53,7 +52,6 @@
"husky": ">=7.0.4",
"lint-staged": "^12.1.2",
"netlify-plugin-cache-nextjs": "^1.6.1",
"next-sitemap": "^1.6.203",
"prettier": "^2.5.0"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# *
User-agent: *
Allow: /

# Host
Host: https://mikebifulco.com

# Sitemaps
Sitemap: https://mikebifulco.com/sitemap.xml
4 changes: 2 additions & 2 deletions src/components/RelatedContent/RelatedContentLinksByTag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Link, SimpleGrid, Text, useTheme } from '@chakra-ui/react';
import { NextLink } from 'next/link';
import NextLink from 'next/link';

import TagDictionary, { getTagInformation } from '../../data/ConvertKitTags';

Expand Down Expand Up @@ -36,7 +36,7 @@ const RelatedContentLinksByTag = ({ tags = DEFAULT_TAGS_TO_DISPLAY }) => {
href={`/tags/${tag}`}
key={`related-content-${tag}`}
>
Articles {tagInformation.label}
{`Articles ${tagInformation.label}`}
</Link>
);
})}
Expand Down
3 changes: 2 additions & 1 deletion src/components/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ const SEO = ({
content={image ? `summary_large_image` : `summary`}
/>
<meta name="twitter:title" content={metaTitle} />
<meta name="twitter:creator" content={author?.name || siteAuthor?.name} />
<meta name="twitter:creator" content="@irreverentmike" />
<meta name="twitter:description" content={metaDescription} />
<meta name="twitter:site" content="@irreverentmike" />

<meta
name="og:title"
Expand Down
26 changes: 26 additions & 0 deletions src/lib/staticPagesLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from 'fs';
import { join } from 'path';

import config from '../config';

const { siteUrl } = config;

export const getStaticPageUrls = () => {
const staticPagesDirectory = join(process.cwd(), 'src', 'pages');
const staticPages = fs
.readdirSync(staticPagesDirectory)
.filter((staticPage) => {
return ![
'_app.js',
'_document.js',
'[slug].js',
'index.js',
'_error.js',
].includes(staticPage);
})
.map((staticPagePath) => {
return `${siteUrl}/${staticPagePath.replace('.js', '')}`;
});

return staticPages;
};
9 changes: 9 additions & 0 deletions src/pages/api/rss.xml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getAllPosts } from '../../lib/blog';
import { generateRSSFeed } from '../../utils/rss';

export default async function handler(req, res) {
const posts = await getAllPosts();
const feed = generateRSSFeed(posts);

res.setHeader('Content-Type', 'text/xml').status(200).send(feed);
}
43 changes: 43 additions & 0 deletions src/pages/api/sitemap.xml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { getStaticPageUrls } from '../../lib/staticPagesLoader';
import { getAllPosts } from '../../lib/blog';
import { getAllTags } from '../../lib/tags';
import config from '../../config';

const { siteUrl } = config;

const urlEntryForPage = (url, frequency = 'daily', priority = 1.0) => `
<url>
<loc>${url}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>${frequency}</changefreq>
<priority>${priority}</priority>
</url>
`;

export default async function handler(req, res) {
const staticPageUrls = getStaticPageUrls();

const allPostUrls = (await getAllPosts()).map(
(post) => `${siteUrl}/posts/${post.frontmatter.path}`
);

const allTagUrls = Array.from((await getAllTags()).allTags).map(
(tag) => `${siteUrl}/tags/${tag}`
);

const rssURl = `${siteUrl}/rss.xml`;
const allUrls = [
siteUrl,
rssURl,
...staticPageUrls,
...allPostUrls,
...allTagUrls,
];

const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${allUrls.map((page) => urlEntryForPage(page)).join('')}
</urlset>
`;
res.setHeader('Content-Type', 'text/xml').status(200).send(sitemap);
}
3 changes: 0 additions & 3 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { DefaultLayout } from '../components/Layouts';
import { Image, PostFeed, SEO } from '../components';

import { getAllPosts } from '../lib/blog';
import { generateRSSFeed } from '../utils/rss';

export async function getStaticProps() {
const posts = await getAllPosts();

generateRSSFeed(posts);

return {
props: {
posts,
Expand Down
8 changes: 4 additions & 4 deletions src/pages/shop.js → src/pages/shop/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';

import { Image, SEO } from '../components';
import { DefaultLayout as Layout } from '../components/Layouts';
import { Image, SEO } from '../../components';
import { DefaultLayout as Layout } from '../../components/Layouts';

import * as classes from '../styles/shop.module.scss';
import SoldOut from '../components/soldOut';
import * as classes from '../../styles/shop.module.scss';
import SoldOut from '../../components/soldOut';

const Shop = () => (
<Layout>
Expand Down
17 changes: 6 additions & 11 deletions src/pages/tags.js → src/pages/tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import PropTypes from 'prop-types';
import Link from 'next/link';
import { Heading, SimpleGrid, Text, useTheme } from '@chakra-ui/react';

import { getAllTags } from '../lib/tags';
import { getAllTags } from '../../lib/tags';

import { Tag, NewsletterSignup } from '../components';
import { DefaultLayout as Layout } from '../components/Layouts';

import { SEO } from '../components';
import { Tag, NewsletterSignup, SEO } from '../../components';
import { DefaultLayout as Layout } from '../../components/Layouts';

export const getStaticProps = async () => {
const tags = await getAllTags();
Expand All @@ -36,12 +34,9 @@ const TagsPage = ({ tags }) => {
</Heading>
<SimpleGrid minChildWidth="15ch" spacingY="1ch" fontSize="large">
{tags?.map((tag) => (
<Link href={`/tags/${tag}/`} key={`tag-${tag}`}>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a>
<Tag>{tag}</Tag>
</a>
</Link>
<Tag url={`/tags/${tag.name || tag}/`} key={`tag-${tag.name || tag}`}>
{tag.name || tag}
</Tag>
))}
</SimpleGrid>
<NewsletterSignup />
Expand Down
6 changes: 3 additions & 3 deletions src/pages/work.js → src/pages/work/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import PropTypes from 'prop-types';

import { Box, Heading, Stack, Text, useTheme } from '@chakra-ui/react';

import { DefaultLayout } from '../components/Layouts';
import { ExternalWorkItem, SEO } from '../components';
import { DefaultLayout } from '../../components/Layouts';
import { ExternalWorkItem, SEO } from '../../components';

import { getAllExternalReferences } from '../lib/external-references';
import { getAllExternalReferences } from '../../lib/external-references';

export async function getStaticProps() {
const articles = await getAllExternalReferences();
Expand Down
11 changes: 2 additions & 9 deletions src/utils/rss.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { rules } from 'eslint-config-prettier';
import { Feed } from 'feed';
import fs from 'fs';

import config from '../config';

export const generateRSSFeed = (posts) => {
if (process.env.NODE_ENV === 'development') {
return;
}

const { author, description, siteUrl, title } = config;

const feed = new Feed({
Expand Down Expand Up @@ -39,8 +33,7 @@ export const generateRSSFeed = (posts) => {
author: [author],
date: new Date(date),
});

// this will be mikebifulco.com/rss.xml
fs.writeFileSync('public/rss.xml', feed.rss2());
});

return feed.rss2();
};
21 changes: 0 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,6 @@
resolved "https://registry.yarnpkg.com/@cloudinary/url-gen/-/url-gen-1.2.0.tgz#f1ce33d2b48a007685ca050d22fe32592481ded7"
integrity sha512-Nd42dVANphz4o3dGc3qnZSSEvpKWFFRqKsBkUuH/5UZOQrBEyN0/cKVLoM1v8YaAm2Th2gx3yVIbwzMV1bWlCg==

"@corex/deepmerge@^2.6.34":
version "2.6.34"
resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-2.6.34.tgz#8dd084f2bcc9cf54f6b1210a1aebd25206de2a84"
integrity sha512-5l3bQRGOoCJ1nYTxEaOW/MRuwNDq32KYatWO5rwOlOzxY4beVCrxDBaDBX5wpDn0PYm0QAul/vAC9GDHShEbTw==

"@ctrl/tinycolor@^3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.4.0.tgz#c3c5ae543c897caa9c2a68630bed355be5f9990f"
Expand Down Expand Up @@ -4907,13 +4902,6 @@ markdown-escapes@^1.0.0:
resolved "https://registry.yarnpkg.com/markdown-escapes/-/markdown-escapes-1.0.4.tgz#c95415ef451499d7602b91095f3c8e8975f78535"
integrity sha512-8z4efJYk43E0upd0NbVXwgSTQs6cT3T06etieCMEg7dRbzCbxUCK/GHlX8mhHRDcp+OLlHkPKsvqQTCvsRl2cg==

matcher@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/matcher/-/matcher-4.0.0.tgz#a42a05a09aaed92e2d241eb91fddac689461ea51"
integrity sha512-S6x5wmcDmsDRRU/c2dkccDwQPXoFczc5+HpQ2lON8pnvHlnvHAHj5WlLVvw6n6vNyHuVugYrFohYxbS+pvFpKQ==
dependencies:
escape-string-regexp "^4.0.0"

md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
Expand Down Expand Up @@ -5411,15 +5399,6 @@ next-mdx-remote@^3.0.8:
esbuild "^0.12.9"
pkg-dir "^5.0.0"

next-sitemap@^1.6.203:
version "1.6.203"
resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-1.6.203.tgz#bfa2e67fea2bab1efed60cda743e7f98dc00bb46"
integrity sha512-WigcoqIUNbXQa2GnwOiCOydGx/XHCS4kRtIPNEsc8DGX2XvJtbAJKRxcidZZ2KihTAtwwCu1XQ4Hbof4mJbvLg==
dependencies:
"@corex/deepmerge" "^2.6.34"
matcher "^4.0.0"
minimist "^1.2.5"

next@^12.0.4:
version "12.0.4"
resolved "https://registry.yarnpkg.com/next/-/next-12.0.4.tgz#096578b320f0faf0bd51798decb39aaf00052efe"
Expand Down