Skip to content

Commit 8648380

Browse files
author
Alex Patterson
committed
Merge branch 'dev' into feature/code-block-fix
2 parents 04f283a + aec448a commit 8648380

7 files changed

Lines changed: 154 additions & 18 deletions

File tree

frontend/main/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ yarn-error.log*
3232

3333
# vercel
3434
.vercel
35-
*.env
35+
*.env
36+
37+
public/robots.txt
38+
public/sitemap.xml

frontend/main/next-sitemap.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
siteUrl: process.env.SITE_URL || 'https://codingcat.dev',
3+
generateRobotsTxt: true,
4+
sitemapSize: 7000,
5+
exclude: ['/admin*', '/user*', '/server-sitemap.xml'],
6+
robotsTxtOptions: {
7+
policies: [
8+
{
9+
userAgent: '*',
10+
allow: '/',
11+
disallow: ['/admin*', '/user*'],
12+
},
13+
],
14+
additionalSitemaps: [
15+
`${process.env.SITE_URL || 'https://codingcat.dev'}/server-sitemap.xml`,
16+
],
17+
},
18+
};

frontend/main/package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/main/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"emulate:firebase": "npm run --prefix ./../../backend/firebase/ emulated",
1111
"emulate:next": "cross-env NODE_OPTIONS='--inspect=9230' FIRESTORE_EMULATOR_HOST='localhost:8080' NEXT_PUBLIC_FB_AUTH_HOST='http://localhost:9099' NEXT_PUBLIC_FB_DB_HOST='localhost:9000' NEXT_PUBLIC_FB_FS_HOST='localhost:8080' NEXT_PUBLIC_CS_HOST='localhost:9199' NEXT_PUBLIC_FB_FN_HOST='localhost:5001' next dev",
1212
"build": "next build",
13+
"postbuild": "next-sitemap",
1314
"start": "next start -p 3000",
1415
"lint": "next lint"
1516
},
@@ -80,6 +81,7 @@
8081
"autoprefixer": "^10.0.2",
8182
"eslint-config-next": "11.1.2",
8283
"eslint-config-prettier": "^8.3.0",
84+
"next-sitemap": "^1.6.192",
8385
"postcss": "^8.2.1",
8486
"postcss-preset-env": "^6.7.0",
8587
"prettier": "^2.2.1",

frontend/main/src/pages/[...permalink].tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,25 @@ export default function Post({
9494
}
9595

9696
export async function getStaticPaths(): Promise<{
97-
paths: { params: { type: PostType; slug: string } }[];
97+
paths: { params: { permalink: string[] } }[];
9898
fallback: boolean;
9999
}> {
100-
const paths: { params: { type: PostType; slug: string } }[] = [];
101-
[PostType.post, PostType.tutorial, PostType.podcast, PostType.page].forEach(
102-
async (postType) => {
103-
const docData = await postsService(postType);
104-
for (const doc of docData) {
105-
paths.push({
106-
params: {
107-
type: doc.type,
108-
slug: doc.slug,
109-
},
110-
});
111-
}
100+
const paths: { params: { permalink: string[] } }[] = [];
101+
for (const postType of [
102+
PostType.post,
103+
PostType.tutorial,
104+
PostType.podcast,
105+
PostType.page,
106+
]) {
107+
const docData = await postsService(postType);
108+
for (const doc of docData) {
109+
paths.push({
110+
params: {
111+
permalink: [doc.type, doc.slug],
112+
},
113+
});
112114
}
113-
);
115+
}
114116
return {
115117
paths,
116118
fallback: true,

frontend/main/src/pages/course/[coursePath]/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getSite,
66
getStripeProduct,
77
postBySlugService,
8+
postsService,
89
} from '@/services/serversideApi';
910

1011
import { Post as PostModel, PostType } from '@/models/post.model';
@@ -74,11 +75,22 @@ export default function CoursePage({
7475
}
7576

7677
export async function getStaticPaths(): Promise<{
77-
paths: { params: { type: PostType; slug: string } }[];
78+
paths: { params: { coursePath: string } }[];
7879
fallback: boolean;
7980
}> {
81+
const paths: { params: { coursePath: string } }[] = [];
82+
for (const postType of [PostType.course]) {
83+
const docData = await postsService(postType);
84+
for (const doc of docData) {
85+
paths.push({
86+
params: {
87+
coursePath: doc.slug,
88+
},
89+
});
90+
}
91+
}
8092
return {
81-
paths: [],
93+
paths,
8294
fallback: true,
8395
};
8496
}
@@ -128,7 +140,7 @@ export async function getStaticProps({
128140
if (productId) {
129141
product = await getStripeProduct(productId);
130142
if (product) {
131-
console.log('Product Found and passed.');
143+
console.log(`${coursePath} has product: `, product.id);
132144
}
133145
}
134146

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// pages/server-sitemap.xml/index.tsx
2+
3+
import { getServerSideSitemap, ISitemapField } from 'next-sitemap';
4+
import { GetServerSideProps } from 'next';
5+
import { PostType } from '@/models/post.model';
6+
import { postsService } from '@/services/serversideApi';
7+
8+
const url = `${process.env.SITE_URL || 'https://codingcat.dev'}`;
9+
10+
export const getServerSideProps: GetServerSideProps = async (ctx) => {
11+
const fields: ISitemapField[] = [];
12+
for (const postType of [
13+
PostType.post,
14+
PostType.tutorial,
15+
PostType.podcast,
16+
PostType.page,
17+
PostType.course,
18+
]) {
19+
const docData = await postsService(postType);
20+
for (const doc of docData) {
21+
fields.push({
22+
loc: `${url}/${doc.type}/${doc.slug}`,
23+
changefreq: 'daily',
24+
priority: 0.7,
25+
lastmod: new Date().toISOString(),
26+
});
27+
}
28+
}
29+
return getServerSideSitemap(ctx, fields);
30+
};
31+
32+
// Default export to prevent next.js errors
33+
const Named = () => {};
34+
export default Named;

0 commit comments

Comments
 (0)