From 1333e7d96d80cc358050840bae82491c241df997 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sun, 14 Nov 2021 09:00:30 -0500 Subject: [PATCH 01/12] add creator and site --- src/components/seo.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/seo.js b/src/components/seo.js index ff8954ce..b50e04f3 100644 --- a/src/components/seo.js +++ b/src/components/seo.js @@ -88,8 +88,9 @@ const SEO = ({ content={image ? `summary_large_image` : `summary`} /> - + + Date: Sun, 14 Nov 2021 09:41:34 -0500 Subject: [PATCH 02/12] no longer using next-sitemap --- next-sitemap.js | 5 ----- package.json | 4 +--- public/robots.txt | 9 +++++++++ yarn.lock | 21 --------------------- 4 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 next-sitemap.js create mode 100644 public/robots.txt diff --git a/next-sitemap.js b/next-sitemap.js deleted file mode 100644 index 0f506a10..00000000 --- a/next-sitemap.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - siteUrl: process.env.SITE_URL || 'https://mikebifulco.com', - generateRobotsTxt: process.env.CONTEXT === 'production', // only generate robots.txt for prod - // ...other options -}; diff --git a/package.json b/package.json index 96b9cfe2..dfaaa010 100644 --- a/package.json +++ b/package.json @@ -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", @@ -53,7 +52,6 @@ "husky": ">=7.0.4", "lint-staged": "^11.2.6", "netlify-plugin-cache-nextjs": "^1.6.1", - "next-sitemap": "^1.6.203", "prettier": "^2.4.1" }, "repository": { diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 00000000..c59e0001 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,9 @@ +# * +User-agent: * +Allow: / + +# Host +Host: https://mikebifulco.com + +# Sitemaps +Sitemap: https://mikebifulco.com/sitemap.xml \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2273d111..0b199e05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -833,11 +833,6 @@ dependencies: "@chakra-ui/utils" "1.9.0" -"@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" @@ -4887,13 +4882,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" @@ -5386,15 +5374,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.3: version "12.0.3" resolved "https://registry.yarnpkg.com/next/-/next-12.0.3.tgz#325732ceb4193306a9a31912815fc570d1a66641" From 3fa88571c85e2a82a34142a462b1143c18db60c1 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sun, 14 Nov 2021 09:41:47 -0500 Subject: [PATCH 03/12] new pages structure and sitemap generation --- src/pages/{shop.js => shop/index.js} | 13 +++--- src/pages/sitemap.xml.js | 65 ++++++++++++++++++++++++++++ src/pages/{tags.js => tags/index.js} | 10 ++--- src/pages/{work.js => work/index.js} | 6 +-- 4 files changed, 80 insertions(+), 14 deletions(-) rename src/pages/{shop.js => shop/index.js} (69%) create mode 100644 src/pages/sitemap.xml.js rename src/pages/{tags.js => tags/index.js} (76%) rename src/pages/{work.js => work/index.js} (89%) diff --git a/src/pages/shop.js b/src/pages/shop/index.js similarity index 69% rename from src/pages/shop.js rename to src/pages/shop/index.js index 5b0a110f..0cee7e8a 100644 --- a/src/pages/shop.js +++ b/src/pages/shop/index.js @@ -1,11 +1,11 @@ import React from 'react'; -import Image from 'next/image' +import Image from 'next/image'; -import { DefaultLayout as Layout } from '../components/Layouts'; -import SEO from '../components/seo'; +import { DefaultLayout as Layout } from '../../components/Layouts'; +import SEO from '../../components/seo'; -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 = () => ( @@ -23,7 +23,8 @@ const Shop = () => ( {/* eslint-disable max-len */} egg sticker {/* eslint-enable max-len */} diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js new file mode 100644 index 00000000..c8585431 --- /dev/null +++ b/src/pages/sitemap.xml.js @@ -0,0 +1,65 @@ +import fs from 'fs'; +import { join } from 'path'; + +import { getAllPosts, getAllExternalReferences } from '../lib/blog'; +import { getAllTags } from '../lib/tags'; +import config from '../config'; + +const { siteUrl } = config; + +const urlEntryForPage = (url, frequency = 'daily') => ` + + ${url} + ${new Date().toISOString()} + ${frequency} + 1.0 + +`; + +export const getServerSideProps = async ({ res }) => { + const staticPagesDirectory = join(process.cwd(), 'src', 'pages'); + const staticPages = fs + .readdirSync(staticPagesDirectory) + .filter((staticPage) => { + return ![ + '[slug].js', + '_app.js', + '_document.js', + '_error.js', + 'sitemap.xml.js', + ].includes(staticPage); + }) + .map((staticPagePath) => { + return `${siteUrl}/${staticPagePath.replace('.js', '')}`; + }); + + const allPostUrls = (await getAllPosts()).map( + (post) => `${siteUrl}/${post.frontmatter.path}` + ); + + const allTagUrls = Array.from((await getAllTags()).allTags).map( + (tag) => `${siteUrl}/tags/${tag}` + ); + + console.log(allPostUrls); + + const sitemap = ` + + ${staticPages.map((page) => urlEntryForPage(page)).join('')} + ${allPostUrls.map((post) => urlEntryForPage(post)).join('')} + ${allTagUrls.map((tag) => urlEntryForPage(tag)).join('')} + + `; + + res.setHeader('Content-Type', 'text/xml'); + res.write(sitemap); + res.end(); + + return { + props: {}, + }; +}; + +const Sitemap = () => {}; + +export default Sitemap; diff --git a/src/pages/tags.js b/src/pages/tags/index.js similarity index 76% rename from src/pages/tags.js rename to src/pages/tags/index.js index 128d96c5..4030e1d5 100644 --- a/src/pages/tags.js +++ b/src/pages/tags/index.js @@ -4,12 +4,12 @@ import PropTypes from 'prop-types'; // Components import Link from 'next/link'; -import Tag from '../components/tag'; -import { DefaultLayout as Layout } from '../components/Layouts'; +import Tag from '../../components/tag'; +import { DefaultLayout as Layout } from '../../components/Layouts'; -import * as classes from '../styles/post.module.scss'; -import * as tagsClasses from '../styles/tagsPage.module.scss'; -import { SEO } from '../components'; +import * as classes from '../../styles/post.module.scss'; +import * as tagsClasses from '../../styles/tagsPage.module.scss'; +import { SEO } from '../../components'; const TagsPage = ({ tags }) => ( diff --git a/src/pages/work.js b/src/pages/work/index.js similarity index 89% rename from src/pages/work.js rename to src/pages/work/index.js index a4428096..07bdb999 100644 --- a/src/pages/work.js +++ b/src/pages/work/index.js @@ -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(); From 887efbc0a17af06d7a0c620a1d584ad928166b1e Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sun, 14 Nov 2021 09:50:23 -0500 Subject: [PATCH 04/12] fs can't be used on client-side --- src/lib/staticPagesLoader.js | 26 ++++++++++++++++++++++++++ src/pages/sitemap.xml.js | 26 ++++---------------------- 2 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 src/lib/staticPagesLoader.js diff --git a/src/lib/staticPagesLoader.js b/src/lib/staticPagesLoader.js new file mode 100644 index 00000000..b05be9fa --- /dev/null +++ b/src/lib/staticPagesLoader.js @@ -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 ![ + '[slug].js', + '_app.js', + '_document.js', + '_error.js', + 'sitemap.xml.js', + ].includes(staticPage); + }) + .map((staticPagePath) => { + return `${siteUrl}/${staticPagePath.replace('.js', '')}`; + }); + + return staticPages; +}; diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js index c8585431..dd7e59a2 100644 --- a/src/pages/sitemap.xml.js +++ b/src/pages/sitemap.xml.js @@ -1,7 +1,5 @@ -import fs from 'fs'; -import { join } from 'path'; - -import { getAllPosts, getAllExternalReferences } from '../lib/blog'; +import { getStaticPageUrls } from '../lib/staticPagesLoader'; +import { getAllPosts } from '../lib/blog'; import { getAllTags } from '../lib/tags'; import config from '../config'; @@ -17,21 +15,7 @@ const urlEntryForPage = (url, frequency = 'daily') => ` `; export const getServerSideProps = async ({ res }) => { - const staticPagesDirectory = join(process.cwd(), 'src', 'pages'); - const staticPages = fs - .readdirSync(staticPagesDirectory) - .filter((staticPage) => { - return ![ - '[slug].js', - '_app.js', - '_document.js', - '_error.js', - 'sitemap.xml.js', - ].includes(staticPage); - }) - .map((staticPagePath) => { - return `${siteUrl}/${staticPagePath.replace('.js', '')}`; - }); + const staticPageUrls = getStaticPageUrls(); const allPostUrls = (await getAllPosts()).map( (post) => `${siteUrl}/${post.frontmatter.path}` @@ -41,11 +25,9 @@ export const getServerSideProps = async ({ res }) => { (tag) => `${siteUrl}/tags/${tag}` ); - console.log(allPostUrls); - const sitemap = ` - ${staticPages.map((page) => urlEntryForPage(page)).join('')} + ${staticPageUrls.map((page) => urlEntryForPage(page)).join('')} ${allPostUrls.map((post) => urlEntryForPage(post)).join('')} ${allTagUrls.map((tag) => urlEntryForPage(tag)).join('')} From 70c19e6310fee82bcc980e5e6db4e10a6c0ddfb7 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sun, 14 Nov 2021 09:53:56 -0500 Subject: [PATCH 05/12] don't forget `/posts/` --- src/pages/sitemap.xml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js index dd7e59a2..f3bb6796 100644 --- a/src/pages/sitemap.xml.js +++ b/src/pages/sitemap.xml.js @@ -18,7 +18,7 @@ export const getServerSideProps = async ({ res }) => { const staticPageUrls = getStaticPageUrls(); const allPostUrls = (await getAllPosts()).map( - (post) => `${siteUrl}/${post.frontmatter.path}` + (post) => `${siteUrl}/posts/${post.frontmatter.path}` ); const allTagUrls = Array.from((await getAllTags()).allTags).map( From 6163091d74beb23a3c709df6797b405ada3cf814 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sun, 14 Nov 2021 11:15:39 -0500 Subject: [PATCH 06/12] sitemap as API route --- next.config.js | 6 +++++ src/lib/staticPagesLoader.js | 5 ++-- src/pages/api/sitemap.xml.js | 36 +++++++++++++++++++++++++++ src/pages/sitemap.xml.js | 47 ------------------------------------ 4 files changed, 45 insertions(+), 49 deletions(-) create mode 100644 src/pages/api/sitemap.xml.js delete mode 100644 src/pages/sitemap.xml.js diff --git a/next.config.js b/next.config.js index 9c0bb7c1..cdaa9a11 100644 --- a/next.config.js +++ b/next.config.js @@ -21,5 +21,11 @@ module.exports = withBundleAnalyzer( locales: ['en'], defaultLocale: 'en', }, + rewrites: async () => [ + { + source: '/sitemap.xml', + destination: '/api/sitemap.xml', + }, + ], }) ); diff --git a/src/lib/staticPagesLoader.js b/src/lib/staticPagesLoader.js index b05be9fa..d674ae02 100644 --- a/src/lib/staticPagesLoader.js +++ b/src/lib/staticPagesLoader.js @@ -11,11 +11,12 @@ export const getStaticPageUrls = () => { .readdirSync(staticPagesDirectory) .filter((staticPage) => { return ![ - '[slug].js', '_app.js', '_document.js', - '_error.js', + '[slug].js', + 'index.js', 'sitemap.xml.js', + '_error.js', ].includes(staticPage); }) .map((staticPagePath) => { diff --git a/src/pages/api/sitemap.xml.js b/src/pages/api/sitemap.xml.js new file mode 100644 index 00000000..46bee05f --- /dev/null +++ b/src/pages/api/sitemap.xml.js @@ -0,0 +1,36 @@ +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} + ${new Date().toISOString()} + ${frequency} + ${priority} + +`; + +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 allUrls = [siteUrl, ...staticPageUrls, ...allPostUrls, ...allTagUrls]; + + const sitemap = ` + + ${allUrls.map((page) => urlEntryForPage(page)).join('')} + + `; + res.setHeader('Content-Type', 'text/xml').status(200).send(sitemap); +} diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js deleted file mode 100644 index f3bb6796..00000000 --- a/src/pages/sitemap.xml.js +++ /dev/null @@ -1,47 +0,0 @@ -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') => ` - - ${url} - ${new Date().toISOString()} - ${frequency} - 1.0 - -`; - -export const getServerSideProps = async ({ 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 sitemap = ` - - ${staticPageUrls.map((page) => urlEntryForPage(page)).join('')} - ${allPostUrls.map((post) => urlEntryForPage(post)).join('')} - ${allTagUrls.map((tag) => urlEntryForPage(tag)).join('')} - - `; - - res.setHeader('Content-Type', 'text/xml'); - res.write(sitemap); - res.end(); - - return { - props: {}, - }; -}; - -const Sitemap = () => {}; - -export default Sitemap; From c2f6ea4d7feaadbacc0f819cf56ec34bdc50877c Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Tue, 30 Nov 2021 20:42:55 -0500 Subject: [PATCH 07/12] back to page generation rather than API --- next.config.js | 6 ---- src/pages/api/sitemap.xml.js | 36 -------------------- src/pages/sitemap.xml.js | 65 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 42 deletions(-) delete mode 100644 src/pages/api/sitemap.xml.js create mode 100644 src/pages/sitemap.xml.js diff --git a/next.config.js b/next.config.js index cdaa9a11..9c0bb7c1 100644 --- a/next.config.js +++ b/next.config.js @@ -21,11 +21,5 @@ module.exports = withBundleAnalyzer( locales: ['en'], defaultLocale: 'en', }, - rewrites: async () => [ - { - source: '/sitemap.xml', - destination: '/api/sitemap.xml', - }, - ], }) ); diff --git a/src/pages/api/sitemap.xml.js b/src/pages/api/sitemap.xml.js deleted file mode 100644 index 46bee05f..00000000 --- a/src/pages/api/sitemap.xml.js +++ /dev/null @@ -1,36 +0,0 @@ -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} - ${new Date().toISOString()} - ${frequency} - ${priority} - -`; - -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 allUrls = [siteUrl, ...staticPageUrls, ...allPostUrls, ...allTagUrls]; - - const sitemap = ` - - ${allUrls.map((page) => urlEntryForPage(page)).join('')} - - `; - res.setHeader('Content-Type', 'text/xml').status(200).send(sitemap); -} diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js new file mode 100644 index 00000000..b4082302 --- /dev/null +++ b/src/pages/sitemap.xml.js @@ -0,0 +1,65 @@ +import fs from 'fs'; +import { join } from 'path'; + +import { getAllPosts } from '../lib/blog'; +import { getAllTags } from '../lib/tags'; +import config from '../config'; + +const { siteUrl } = config; + +const urlEntryForPage = (url, frequency = 'daily') => ` + + ${url} + ${new Date().toISOString()} + ${frequency} + 1.0 + +`; + +export const getServerSideProps = async ({ res }) => { + const staticPagesDirectory = join(process.cwd(), 'src', 'pages'); + const staticPages = fs + .readdirSync(staticPagesDirectory) + .filter((staticPage) => { + return ![ + 'index.js', + 'api', + '[slug].js', + '_app.js', + '_document.js', + '_error.js', + 'sitemap.xml.js', + ].includes(staticPage); + }) + .map((staticPagePath) => { + return `${siteUrl}/${staticPagePath.replace('.js', '')}`; + }); + + const allPostUrls = (await getAllPosts()).map( + (post) => `${siteUrl}/posts/${post.frontmatter.path}` + ); + + const allTagUrls = Array.from((await getAllTags()).allTags).map( + (tag) => `${siteUrl}/tags/${tag}` + ); + + const allUrls = [...staticPages, ...allPostUrls, ...allTagUrls]; + + const sitemap = ` + + ${allUrls.map((page) => urlEntryForPage(page)).join('')} + + `; + + res.setHeader('Content-Type', 'text/xml'); + res.write(sitemap); + res.end(); + + return { + props: {}, + }; +}; + +const Sitemap = () => {}; + +export default Sitemap; From 358a9c322083d7cbe5a8922b0646c65827ca9199 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Tue, 30 Nov 2021 20:44:01 -0500 Subject: [PATCH 08/12] updated beta --- package.json | 2 +- yarn.lock | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 91e61f3b..31b9ea02 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "swr": "^1.0.1" }, "devDependencies": { - "@netlify/plugin-nextjs": "4.0.0-beta.6", + "@netlify/plugin-nextjs": "4.0.0-beta.12", "@next/eslint-plugin-next": "^12.0.4", "eslint": "<8.0.0", "eslint-config-next": "^12.0.4", diff --git a/yarn.lock b/yarn.lock index 96626647..7bbd5758 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1079,6 +1079,13 @@ path-exists "^4.0.0" readdirp "^3.4.0" +"@netlify/functions@^0.10.0": + version "0.10.0" + resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.10.0.tgz#3856b609df1c1d1c7c21773650d1e5b4f81cfaf2" + integrity sha512-NNFADTPnokuoMY1OUhaXlE/Jrzk5lHOl1uB4L/8pw1UJ/CaectZJACMExijbJnqaKIhOQG0WmbBQUh1lgnK/Qg== + dependencies: + is-promise "^4.0.0" + "@netlify/functions@^0.7.2": version "0.7.2" resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.7.2.tgz#9d39553b94e7aaa86dddf515bdbaed3e89998122" @@ -1086,13 +1093,6 @@ dependencies: is-promise "^4.0.0" -"@netlify/functions@^0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.8.0.tgz#0c0a3d5a8efdc6aa469f75acb9df556a317cff1f" - integrity sha512-Ew4Q2ofSBa5aeVOvrHNNEkfCJNmjTkEIr+WkyveOZrcnKQGH/sTtPqVb6HP51NJHNhczBkd3S3KdXfrCB0q0Ig== - dependencies: - is-promise "^4.0.0" - "@netlify/ipx@^0.0.7": version "0.0.7" resolved "https://registry.yarnpkg.com/@netlify/ipx/-/ipx-0.0.7.tgz#56098885577c32319cf161be6dc836ade645231d" @@ -1108,12 +1108,12 @@ ufo "^0.7.9" unstorage "^0.2.8" -"@netlify/plugin-nextjs@4.0.0-beta.6": - version "4.0.0-beta.6" - resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-4.0.0-beta.6.tgz#eb968c83f4844b5bf92fdd4b92cd408bd6afdd72" - integrity sha512-6F18qQ5icHaH7rFPbK7sJJVXmOB9oVr0soeth6Wj+rmC9pg30bo8lv7L8bUX95KfOMfca0/4yh+zSxf40pm/Eg== +"@netlify/plugin-nextjs@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-4.0.0-beta.12.tgz#6a685b1b0b6bb2b3de93e5028188a0f6ce3dcbdc" + integrity sha512-40WJ8mZZQKPJjPFW3nl5DrV32hZkOnpSnJjjLPTdUWrEOUKsliz94g77XwhuemiB6REAQOAByJT1qVWNMNmxVQ== dependencies: - "@netlify/functions" "^0.8.0" + "@netlify/functions" "^0.10.0" "@netlify/ipx" "^0.0.7" "@vercel/node" "^1.11.2-canary.4" chalk "^4.1.2" From 12cf373a4d55aad2255b5e2e8389455d3cc19588 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Tue, 30 Nov 2021 20:45:07 -0500 Subject: [PATCH 09/12] deps --- package.json | 6 +++--- yarn.lock | 37 ++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 31b9ea02..ed8cc2bf 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@mdx-js/react": "^1.6.22", "@next/bundle-analyzer": "^12.0.4", "@next/mdx": "^12.0.4", - "date-fns": "^2.26.0", + "date-fns": "^2.27.0", "fathom-client": "^3.2.0", "feed": "^4.2.2", "framer-motion": "^5.3.3", @@ -39,9 +39,9 @@ "react-dom": "^17.0.2", "remark": "^14.0.2", "remark-html": "^15.0.1", - "sass": "^1.43.5", + "sass": "^1.44.0", "sharp": "^0.29.3", - "swr": "^1.0.1" + "swr": "^1.1.0" }, "devDependencies": { "@netlify/plugin-nextjs": "4.0.0-beta.12", diff --git a/yarn.lock b/yarn.lock index 7bbd5758..9d536c49 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2521,10 +2521,10 @@ data-uri-to-buffer@3.0.1: resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636" integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og== -date-fns@^2.26.0: - version "2.26.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.26.0.tgz#fa45305543c392c4f914e50775fd2a4461e60fbd" - integrity sha512-VQI812dRi3cusdY/fhoBKvc6l2W8BPWU1FNVnFH9Nttjx4AFBRzfSVb/Eyc7jBT6e9sg1XtAGsYpBQ6c/jygbg== +date-fns@^2.27.0: + version "2.27.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.27.0.tgz#e1ff3c3ddbbab8a2eaadbb6106be2929a5a2d92b" + integrity sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q== debug@2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9: version "2.6.9" @@ -2644,11 +2644,6 @@ depd@~1.1.2: resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= -dequal@2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.2.tgz#85ca22025e3a87e65ef75a7a437b35284a7e319d" - integrity sha512-q9K8BlJVxK7hQYqa6XISGmBZbtQQWVXSrRrWreHC94rMt1QL/Impruc+7p2CYSYuVIUr+YCt6hjrs1kkdJRTug== - des.js@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843" @@ -4024,6 +4019,11 @@ image-size@1.0.0: dependencies: queue "6.0.2" +immutable@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.0.0.tgz#b86f78de6adef3608395efb269a91462797e2c23" + integrity sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw== + import-fresh@^3.0.0, import-fresh@^3.1.0, import-fresh@^3.2.1: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" @@ -6623,12 +6623,13 @@ safe-regex@^1.1.0: resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -sass@^1.43.5: - version "1.43.5" - resolved "https://registry.yarnpkg.com/sass/-/sass-1.43.5.tgz#25a9d91dd098793ef7229d7b04dd3daae2fc4a65" - integrity sha512-WuNm+eAryMgQluL7Mbq9M4EruyGGMyal7Lu58FfnRMVWxgUzIvI7aSn60iNt3kn5yZBMR7G84fAGDcwqOF5JOg== +sass@^1.44.0: + version "1.44.0" + resolved "https://registry.yarnpkg.com/sass/-/sass-1.44.0.tgz#619aa0a2275c097f9af5e6b8fe8a95e3056430fb" + integrity sha512-0hLREbHFXGQqls/K8X+koeP+ogFRPF4ZqetVB19b7Cst9Er8cOR0rc6RU7MaI4W1JmUShd1BPgPoeqmmgMMYFw== dependencies: chokidar ">=3.0.0 <4.0.0" + immutable "^4.0.0" sax@^1.2.4: version "1.2.4" @@ -7279,12 +7280,10 @@ supports-color@^9.0.2: resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-9.1.0.tgz#558963681dafeff41ed68220488cbf438d29f351" integrity sha512-lOCGOTmBSN54zKAoPWhHkjoqVQ0MqgzPE5iirtoSixhr0ZieR/6l7WZ32V53cvy9+1qghFnIk7k52p991lKd6g== -swr@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/swr/-/swr-1.0.1.tgz#15f62846b87ee000e52fa07812bb65eb62d79483" - integrity sha512-EPQAxSjoD4IaM49rpRHK0q+/NzcwoT8c0/Ylu/u3/6mFj/CWnQVjNJ0MV2Iuw/U+EJSd2TX5czdAwKPYZIG0YA== - dependencies: - dequal "2.0.2" +swr@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/swr/-/swr-1.1.0.tgz#7710cdbc5ff664c13e41fba6a1fa4734f82aba35" + integrity sha512-MFL3mkl752Uap81nLA1tEu7vQmikPamSziW+6dBidYKAo4oLOlUx/x5GZy4ZCkCwfZe2uedylkz1UMGnatUX4g== table@^6.0.9: version "6.7.2" From e9fc6d4188ae58a80b1274a7e1ef8e2d3aeb7930 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Wed, 1 Dec 2021 18:12:26 -0500 Subject: [PATCH 10/12] eff emmell --- package.json | 2 +- yarn.lock | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index ed8cc2bf..337d4db5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "swr": "^1.1.0" }, "devDependencies": { - "@netlify/plugin-nextjs": "4.0.0-beta.12", + "@netlify/plugin-nextjs": "4.0.0-beta.6", "@next/eslint-plugin-next": "^12.0.4", "eslint": "<8.0.0", "eslint-config-next": "^12.0.4", diff --git a/yarn.lock b/yarn.lock index 9d536c49..6dce1e6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1079,13 +1079,6 @@ path-exists "^4.0.0" readdirp "^3.4.0" -"@netlify/functions@^0.10.0": - version "0.10.0" - resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.10.0.tgz#3856b609df1c1d1c7c21773650d1e5b4f81cfaf2" - integrity sha512-NNFADTPnokuoMY1OUhaXlE/Jrzk5lHOl1uB4L/8pw1UJ/CaectZJACMExijbJnqaKIhOQG0WmbBQUh1lgnK/Qg== - dependencies: - is-promise "^4.0.0" - "@netlify/functions@^0.7.2": version "0.7.2" resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.7.2.tgz#9d39553b94e7aaa86dddf515bdbaed3e89998122" @@ -1093,6 +1086,13 @@ dependencies: is-promise "^4.0.0" +"@netlify/functions@^0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-0.8.0.tgz#0c0a3d5a8efdc6aa469f75acb9df556a317cff1f" + integrity sha512-Ew4Q2ofSBa5aeVOvrHNNEkfCJNmjTkEIr+WkyveOZrcnKQGH/sTtPqVb6HP51NJHNhczBkd3S3KdXfrCB0q0Ig== + dependencies: + is-promise "^4.0.0" + "@netlify/ipx@^0.0.7": version "0.0.7" resolved "https://registry.yarnpkg.com/@netlify/ipx/-/ipx-0.0.7.tgz#56098885577c32319cf161be6dc836ade645231d" @@ -1108,12 +1108,12 @@ ufo "^0.7.9" unstorage "^0.2.8" -"@netlify/plugin-nextjs@4.0.0-beta.12": - version "4.0.0-beta.12" - resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-4.0.0-beta.12.tgz#6a685b1b0b6bb2b3de93e5028188a0f6ce3dcbdc" - integrity sha512-40WJ8mZZQKPJjPFW3nl5DrV32hZkOnpSnJjjLPTdUWrEOUKsliz94g77XwhuemiB6REAQOAByJT1qVWNMNmxVQ== +"@netlify/plugin-nextjs@4.0.0-beta.6": + version "4.0.0-beta.6" + resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-4.0.0-beta.6.tgz#eb968c83f4844b5bf92fdd4b92cd408bd6afdd72" + integrity sha512-6F18qQ5icHaH7rFPbK7sJJVXmOB9oVr0soeth6Wj+rmC9pg30bo8lv7L8bUX95KfOMfca0/4yh+zSxf40pm/Eg== dependencies: - "@netlify/functions" "^0.10.0" + "@netlify/functions" "^0.8.0" "@netlify/ipx" "^0.0.7" "@vercel/node" "^1.11.2-canary.4" chalk "^4.1.2" From 4485b86b8af4a1e2f745d50410951188d5bd5ddb Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sat, 4 Dec 2021 08:39:31 -0500 Subject: [PATCH 11/12] rss and sitemap as api routes --- next.config.js | 10 ++++++ src/lib/staticPagesLoader.js | 1 - src/pages/api/rss.xml.js | 9 +++++ src/pages/api/sitemap.xml.js | 43 ++++++++++++++++++++++++ src/pages/index.js | 3 -- src/pages/sitemap.xml.js | 65 ------------------------------------ src/utils/rss.js | 11 ++---- 7 files changed, 64 insertions(+), 78 deletions(-) create mode 100644 src/pages/api/rss.xml.js create mode 100644 src/pages/api/sitemap.xml.js delete mode 100644 src/pages/sitemap.xml.js diff --git a/next.config.js b/next.config.js index 9c0bb7c1..9f82cde5 100644 --- a/next.config.js +++ b/next.config.js @@ -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', + }, + ], }) ); diff --git a/src/lib/staticPagesLoader.js b/src/lib/staticPagesLoader.js index d674ae02..d9d27787 100644 --- a/src/lib/staticPagesLoader.js +++ b/src/lib/staticPagesLoader.js @@ -15,7 +15,6 @@ export const getStaticPageUrls = () => { '_document.js', '[slug].js', 'index.js', - 'sitemap.xml.js', '_error.js', ].includes(staticPage); }) diff --git a/src/pages/api/rss.xml.js b/src/pages/api/rss.xml.js new file mode 100644 index 00000000..88a9a27e --- /dev/null +++ b/src/pages/api/rss.xml.js @@ -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); +} diff --git a/src/pages/api/sitemap.xml.js b/src/pages/api/sitemap.xml.js new file mode 100644 index 00000000..ae776345 --- /dev/null +++ b/src/pages/api/sitemap.xml.js @@ -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} + ${new Date().toISOString()} + ${frequency} + ${priority} + +`; + +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 = ` + + ${allUrls.map((page) => urlEntryForPage(page)).join('')} + + `; + res.setHeader('Content-Type', 'text/xml').status(200).send(sitemap); +} diff --git a/src/pages/index.js b/src/pages/index.js index 2e125887..cf102d54 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -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, diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js deleted file mode 100644 index b4082302..00000000 --- a/src/pages/sitemap.xml.js +++ /dev/null @@ -1,65 +0,0 @@ -import fs from 'fs'; -import { join } from 'path'; - -import { getAllPosts } from '../lib/blog'; -import { getAllTags } from '../lib/tags'; -import config from '../config'; - -const { siteUrl } = config; - -const urlEntryForPage = (url, frequency = 'daily') => ` - - ${url} - ${new Date().toISOString()} - ${frequency} - 1.0 - -`; - -export const getServerSideProps = async ({ res }) => { - const staticPagesDirectory = join(process.cwd(), 'src', 'pages'); - const staticPages = fs - .readdirSync(staticPagesDirectory) - .filter((staticPage) => { - return ![ - 'index.js', - 'api', - '[slug].js', - '_app.js', - '_document.js', - '_error.js', - 'sitemap.xml.js', - ].includes(staticPage); - }) - .map((staticPagePath) => { - return `${siteUrl}/${staticPagePath.replace('.js', '')}`; - }); - - const allPostUrls = (await getAllPosts()).map( - (post) => `${siteUrl}/posts/${post.frontmatter.path}` - ); - - const allTagUrls = Array.from((await getAllTags()).allTags).map( - (tag) => `${siteUrl}/tags/${tag}` - ); - - const allUrls = [...staticPages, ...allPostUrls, ...allTagUrls]; - - const sitemap = ` - - ${allUrls.map((page) => urlEntryForPage(page)).join('')} - - `; - - res.setHeader('Content-Type', 'text/xml'); - res.write(sitemap); - res.end(); - - return { - props: {}, - }; -}; - -const Sitemap = () => {}; - -export default Sitemap; diff --git a/src/utils/rss.js b/src/utils/rss.js index 2ac5a34c..a571a4e6 100644 --- a/src/utils/rss.js +++ b/src/utils/rss.js @@ -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({ @@ -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(); }; From 2a361f940070717020a2910a24cd3809e598722c Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Tue, 7 Dec 2021 12:59:47 -0500 Subject: [PATCH 12/12] bug fixes --- .../RelatedContent/RelatedContentLinksByTag.js | 4 ++-- src/pages/tags/index.js | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/RelatedContent/RelatedContentLinksByTag.js b/src/components/RelatedContent/RelatedContentLinksByTag.js index 90285032..615cc909 100644 --- a/src/components/RelatedContent/RelatedContentLinksByTag.js +++ b/src/components/RelatedContent/RelatedContentLinksByTag.js @@ -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'; @@ -36,7 +36,7 @@ const RelatedContentLinksByTag = ({ tags = DEFAULT_TAGS_TO_DISPLAY }) => { href={`/tags/${tag}`} key={`related-content-${tag}`} > - Articles {tagInformation.label} + {`Articles ${tagInformation.label}`} ); })} diff --git a/src/pages/tags/index.js b/src/pages/tags/index.js index f23cc82a..17747ff3 100644 --- a/src/pages/tags/index.js +++ b/src/pages/tags/index.js @@ -34,12 +34,9 @@ const TagsPage = ({ tags }) => { {tags?.map((tag) => ( - - {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} - - {tag} - - + + {tag.name || tag} + ))}