How to Change the /blog URL Path
Read time: 1 minute
- Mitchell Christ
Creating a website with a blog is effortless with SanityPress. Out of the box, the blog homepage and individual posts are organized under the /blog
URL path.
But what if "blog" doesnโt align with your vision? No problemโcustomizing it to fit your needs is a breeze with a few tweaks to your SanityPress codebase.
In this guide, weโll walk you through the steps to update the blogโs URL path. For this example, weโll show you how to change /blog
to /press
. Letโs dive in!
GROQ queries to update
7 files:
๐ next.config.ts:
// line 30
- destination.internal->._type == 'blog.post' => '/blog/',
+ destination.internal->._type == 'blog.post' => '/press/',
๐ src/app/sitemap.ts
// line 10
- !(metadata.slug.current in ['404', 'blog/*']) &&
+ !(metadata.slug.current in ['404', 'press/*']) &&
// line 21
- 'url': $baseUrl + 'blog/' + metadata.slug.current,
- 'url': $baseUrl + 'press/' + metadata.slug.current,
๐ src/app/(frontend)/[...slug]/page.tsx
// line 26
- !(metadata.slug.current in ['index', 'blog/*'])
+ !(metadata.slug.current in ['index', 'press/*'])
// line 38
- !(metadata.slug.current in ['index', 'blog/*'])
+ !(metadata.slug.current in ['index', 'press/*'])
๐ src/app/(frontend)/blog/[slug]/page.tsx
// line 63
- query: groq`*[_type == 'page' && metadata.slug.current == 'blog/*'][0]{
+ query: groq`*[_type == 'page' && metadata.slug.current == 'press/*'][0]{
๐ src/app/(frontend)/blog/rss.xml/route.ts
// line 15
- 'blog': *[_type == 'page' && metadata.slug.current == 'blog'][0]{
+ 'blog': *[_type == 'page' && metadata.slug.current == 'press'][0]{
๐ src/ui/modules/search/store.ts
// line 68
- !(metadata.slug.current in ['404', 'blog/*']) &&
+ !(metadata.slug.current in ['404', 'press/*']) &&
๐ src/ui/modules/blog/Category.tsx
// line 17
- pathname: '/blog',
+ pathname: '/press',
String values to update
5 files:
๐ src/lib/processMetadata.ts
// line 31
- 'application/rss+xml': '/blog/rss.xml',
+ 'application/rss+xml': '/press/rss.xml',
๐ src/lib/processUrl.ts
// line 13
- const segment = page?._type === 'blog.post' ? 'blog' : null
+ const segment = page?._type === 'blog.post' ? 'press' : null
๐ src/sanity/presentation.ts
// line 25
- route: '/blog/:slug',
+ route: '/press/:slug',
๐ src/sanity/lib/processSlug.ts
// line 17
- const segment = _type === 'blog.post' ? '/blog/' : '/'
+ const segment = _type === 'blog.post' ? '/press/' : '/'
๐ src/sanity/schemaTypes/documents/page.ts
// line 110
- (['blog', 'blog/*'].includes(slug) && VscEdit) ||
+ (['press', 'press/*'].includes(slug) && VscEdit) ||
One last step
Lastly, we want to change the folder name that handles the Next.js routing for the blog pages:
- ๐ src/app/(frontend)/blog/*
๐ src/app/(frontend)/press/*
Let us know below if you'd like further refinements!