Skip to content

Commit

Permalink
feat(config): create website.config.ts with global config and metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Jul 10, 2023
1 parent d9148e3 commit 2220916
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/app/(blog)/author/[author]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function generateMetadata({ params }: Props): Metadata {
const author = getAuthorByUser(params.author)

return {
title: `mfg-b | ${author.name}`,
title: author.name,
description: `Posts written by ${author.name} (${author.user}) <${author.email}>`
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(blog)/categories/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {

export function generateMetadata({ params }: Props): Metadata {
return {
title: `mfg-b | ${getNormalCategoryString(params.category)}`,
title: getNormalCategoryString(params.category),
description: `Posts about ${getNormalCategoryString(
params.category
)} category`
Expand Down
2 changes: 1 addition & 1 deletion src/app/(blog)/categories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { slug } from '@/shared/lib/slug'
import { Folder } from '@/shared/lib/phosphor-icons'

export const metadata: Metadata = {
title: 'mfg-b | Categories',
title: 'Blog Categories',
description: 'Post categories about all kind of things'
}

Expand Down
12 changes: 6 additions & 6 deletions src/app/(blog)/feed/generate-feed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getSortedPosts } from '@/shared/lib/get-sorted-posts'
import { host } from '@/shared/lib/webserver-constants'
import { config } from 'global-config'
import { allPosts } from 'contentlayer/generated'
import { Feed } from 'feed'
import { markdownToHtml } from './markdown-to-html'
Expand All @@ -15,13 +15,13 @@ export function generateFeed() {
title: "Mateus Felipe's interests",
description:
'This is my "corner of internet", where I take some tests, document my studies and write about some subjects I like...',
id: host,
link: host,
favicon: `${host}/assets/brain.png`,
id: config.webserver.host,
link: config.webserver.host,
favicon: `${config.webserver.host}/assets/brain.png`,
copyright: `All rights reserved ${date.getFullYear()}, Mateus Felipe.`,
updated: posts.length > 0 ? new Date(posts[0].date) : date,
feedLinks: {
rss2: `${host}/feed`
rss2: `${config.webserver.host}/feed`
},
docs: 'https://github.com/mateusfg7/mfg-b',
generator: 'Feed for Node.js',
Expand All @@ -34,7 +34,7 @@ export function generateFeed() {

posts.forEach(async post => {
const { name, email, url: authorLink } = post.author_info
const link = `${host}/post/${post.id}`
const link = `${config.webserver.host}/post/${post.id}`

feed.addItem({
link,
Expand Down
3 changes: 3 additions & 0 deletions src/app/(blog)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Footer } from './components/footer'
import { Header } from './components/header'




export default function BlogLayout({
children
}: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(blog)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getSortedPosts } from '@/shared/lib/get-sorted-posts'
import { PostList } from '@/shared/components/post-list'

export const metadata: Metadata = {
title: 'My Knowledge | mfg-b',
title: 'Blog',
description:
'List of my knowledge, reflections, notes and likes about all kind of things.'
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/(blog)/post/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useMDXComponent } from 'next-contentlayer/hooks'
import { allPosts, type Post } from 'contentlayer/generated'

import { slug } from '@/shared/lib/slug'
import { host } from '@/shared/lib/webserver-constants'
import { config } from 'global-config'
import { Folder, CalendarBlank, Clock, Tag } from '@/shared/lib/phosphor-icons'
import { Date } from '@/shared/components/date'
import { TopButton } from './components/top-button'
Expand All @@ -23,7 +23,7 @@ export function generateMetadata({ params }: Props): Metadata {
const post = allPosts.find(post => post.id === params.slug) as Post

return {
title: `mfg-b | ${post.title}`,
title: post.title,
description: post.description,
authors: { name: post.author_info.name, url: post.author_info.url },
keywords: post.tags.split(',').map(tag => tag.trim()),
Expand All @@ -36,7 +36,7 @@ export function generateMetadata({ params }: Props): Metadata {
type: 'article',
url: `https://mfg-b.vercel.app/post/${params.slug}`,
images: {
url: `${host}/post/${post.id}/thumbnail`,
url: `${config.webserver.host}/post/${post.id}/thumbnail`,
width: 1200,
height: 630
}
Expand All @@ -46,9 +46,9 @@ export function generateMetadata({ params }: Props): Metadata {
title: post.title,
description: post.description,
creator: 'Mateus Felipe Gonçalves <[email protected]>',
site: `${host}`,
site: `${config.webserver.host}`,
images: {
url: `${host}/post/${post.id}/og`,
url: `${config.webserver.host}/post/${post.id}/og`,
width: 1200,
height: 630
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/(blog)/post/[slug]/thumbnail/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImageResponse, NextResponse } from 'next/server'
import { FiFolder, FiCalendar, FiClock } from 'react-icons/fi'
import { allPosts } from 'contentlayer/generated'
import { Date } from '@/shared/components/date'
import { host } from '@/shared/lib/webserver-constants'
import { config } from 'global-config'

export const runtime = 'edge'

Expand Down Expand Up @@ -85,7 +85,7 @@ export async function GET(
<FiClock /> {Math.ceil(post.reading_time.minutes)} min read
</span>
</div>
<span style={{ display: 'flex' }}>{host.split('//')[1]}</span>
<span style={{ display: 'flex' }}>{config.webserver.host.split('//')[1]}</span>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(blog)/tag/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {

export function generateMetadata({ params }: Props): Metadata {
return {
title: `mfg-b | ${getNormalTagString(params.tag)}`,
title: getNormalTagString(params.tag),
description: `Posts with tag "${getNormalTagString(params.tag)}"`
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(blog)/tag/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getTagsAndNumberOfPosts } from '@/shared/lib/tags'
import { Tag } from '@/shared/lib/phosphor-icons'

export const metadata: Metadata = {
title: 'mfg-b | Tags',
title: 'Blog Tags',
description: 'Post tags about all kind of things'
}

Expand Down
16 changes: 9 additions & 7 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import type { Metadata } from 'next'
import { config } from 'global-config'

import { Providers } from './providers'

import '@/styles/main.css'
import Script from 'next/script'

export const metadata: Metadata = {
title: 'mfg-b',
description: "Mateus Felipe's notes, articles, reflections and knowledge...",
...config.metadata,
title: {
default: config.metadata.title,
template: `%s | ${config.metadata.title}`
},
colorScheme: 'dark light',
viewport: 'width=device-width, initial-scale=1',
openGraph: {
title: 'mfg-b',
...config.metadata,
type: 'website',
url: 'https://mfg-b.vercel.app/',
description: "Mateus Felipe's notes, articles, reflections and knowledge..."
url: config.webserver.host,
},
twitter: {
title: 'mfg-b',
...config.metadata,
card: 'summary_large_image',
description: "Mateus Felipe's notes, articles, reflections and knowledge..."
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/app/portifolio/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Metadata } from "next"

export const metadata: Metadata = {
title: 'Portifolio',
description:
'List of my projects and sills'
}

export default function PortfolioLayout({
children
}: {
children: React.ReactNode
}) {
return (
<>
{children}
</>
)
}
4 changes: 0 additions & 4 deletions src/app/portifolio/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import { useEffect, useState } from 'react'
import Head from 'next/head'

import {
Header,
Expand Down Expand Up @@ -45,9 +44,6 @@ export default function Page() {

return (
<div className="bg-neutral-1000 text-neutral-300" id="portifolio">
<Head>
<title>Portifólio | Mateus Felipe Gonçalves</title>
</Head>
<Header scrollPosition={scrollPosition} maxScrollValue={maxScrollValue} />
<HomeSection />
<AboutSection />
Expand Down
4 changes: 2 additions & 2 deletions src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MetadataRoute } from 'next'
import { host } from '@/shared/lib/webserver-constants'
import { config } from 'global-config'

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: ['/', '/post/*/thumbnail'],
},
sitemap: `${host}/sitemap.xml`
sitemap: `${config.webserver.host}/sitemap.xml`
}
}
12 changes: 6 additions & 6 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { MetadataRoute } from 'next'
import { getUniqueCategoryList } from '@/shared/lib/categories'
import { getUniqueTagListFromPosts } from '@/shared/lib/tags'
import { host } from '@/shared/lib/webserver-constants'
import { config } from 'global-config'
import { allPosts } from 'contentlayer/generated'
import { slug } from '@/shared/lib/slug'

export default function sitemap(): MetadataRoute.Sitemap {
const commonRoutes = ['', 'categories', 'feed', 'tag', 'portifolio'].map(
route => ({
url: `${host}/${route}`,
url: `${config.webserver.host}/${route}`,
lastModified: new Date().toISOString()
})
)

const tags = getUniqueTagListFromPosts().map(tag => ({
url: `${host}/tag/${slug(tag)}`,
url: `${config.webserver.host}/tag/${slug(tag)}`,
lastModified: new Date().toISOString()
}))
const categories = getUniqueCategoryList().map(category => ({
url: `${host}/categories/${slug(category)}`,
url: `${config.webserver.host}/categories/${slug(category)}`,
lastModified: new Date().toISOString()
}))
const posts = allPosts.map(post => ({
url: `${host}/post/${post.id}`,
url: `${config.webserver.host}/post/${post.id}`,
lastModified: new Date(post.date).toISOString()
}))

Expand All @@ -32,7 +32,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
...categories,
...posts,
{
url: `${host}/author/mateusfg7`,
url: `${config.webserver.host}/author/mateusfg7`,
lastModified: new Date().toISOString()
}
]
Expand Down
1 change: 0 additions & 1 deletion src/shared/lib/webserver-constants.ts

This file was deleted.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
],
"@/*": [
"src/*"
],
"global-config": [
"./website.config.ts"
]
},
"plugins": [
Expand Down
9 changes: 9 additions & 0 deletions website.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const config = {
metadata: {
title: 'Mateus Felipe',
description: "Mateus Felipe's notes, articles, reflections and knowledge..."
},
webserver: {
host: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000'
}
}

0 comments on commit 2220916

Please sign in to comment.