From 662c736ca429bd78cce43aedd576a338806e3d86 Mon Sep 17 00:00:00 2001 From: hta218 Date: Sun, 13 Aug 2023 23:02:47 +0700 Subject: [PATCH] chore: remove logs & clean up --- components/PostListItem.tsx | 3 +-- components/homepage/TypedBios.tsx | 4 ++-- layouts/ListLayout.tsx | 2 +- libs/files.ts | 8 ++------ pages/404.tsx | 3 +-- pages/blog.tsx | 2 +- pages/blog/[...slug].tsx | 8 +------- pages/blog/page/[page].tsx | 2 +- pages/snippets/[...slug].tsx | 4 ---- pages/tags/[tag].tsx | 16 +++++++--------- 10 files changed, 17 insertions(+), 35 deletions(-) diff --git a/components/PostListItem.tsx b/components/PostListItem.tsx index 2050be20..a5002f4b 100644 --- a/components/PostListItem.tsx +++ b/components/PostListItem.tsx @@ -1,9 +1,8 @@ +import { useTranslation } from 'next-i18next' import type { MdxFrontMatter } from '~/types' import { formatDate } from '~/utils/date' import { Link } from './Link' import { Tag } from './Tag' -import { useTranslation } from 'next-i18next' -import { language } from 'gray-matter' export function PostListItem({ frontMatter }: { frontMatter: MdxFrontMatter }) { let { slug, date, title, summary, tags } = frontMatter diff --git a/components/homepage/TypedBios.tsx b/components/homepage/TypedBios.tsx index 04a735e3..a68491c1 100644 --- a/components/homepage/TypedBios.tsx +++ b/components/homepage/TypedBios.tsx @@ -1,12 +1,12 @@ import React from 'react' import Typed from 'typed.js' import { Twemoji } from '../Twemoji' -import { useTranslation } from 'next-i18next' // Import the hook +import { useTranslation } from 'next-i18next' export function TypedBios() { let el = React.useRef(null) let typed = React.useRef(null) - let { t } = useTranslation('common') // Use the hook to get the translation function + let { t } = useTranslation('common') React.useEffect(() => { typed.current = new Typed(el.current, { diff --git a/layouts/ListLayout.tsx b/layouts/ListLayout.tsx index cc2a7f4f..b6c9badd 100644 --- a/layouts/ListLayout.tsx +++ b/layouts/ListLayout.tsx @@ -7,6 +7,7 @@ import { useTranslation } from 'next-i18next' export function ListLayout(props: ListLayoutProps) { let { posts, title, initialDisplayPosts = [], pagination } = props + let { t } = useTranslation('common') let [searchValue, setSearchValue] = useState('') let filteredBlogPosts = posts.filter((frontMatter) => { let searchContent = frontMatter.title + frontMatter.summary + frontMatter.tags.join(' ') @@ -17,7 +18,6 @@ export function ListLayout(props: ListLayoutProps) { let displayPosts = initialDisplayPosts.length > 0 && !searchValue ? initialDisplayPosts : filteredBlogPosts - let { t } = useTranslation('common') // utilitza 'common' si els teus strings estan a common.ts o canvia-ho pel nom adequat return ( <>
diff --git a/libs/files.ts b/libs/files.ts index 2c780523..5c347f10 100644 --- a/libs/files.ts +++ b/libs/files.ts @@ -29,11 +29,8 @@ export function formatSlug(slug: string) { return slug.replace(/\.(mdx|md)/, '') } -export function getCommon(locale) { - // Resol la ruta al fitxer .json basat en l'idioma +export function getCommon(locale: string) { let filePath = path.join(process.cwd(), 'public', 'locales', locale, 'common.json') - - // Llegeix el fitxer .json let rawData = fs.readFileSync(filePath, 'utf8') let data = JSON.parse(rawData) return data @@ -42,11 +39,10 @@ export function getCommon(locale) { export function getFiles(type: string): string[] { let root = process.cwd() let prefixPaths = path.join(root, 'data', type) - let files + let files: string[] try { files = getAllFilesRecursively(prefixPaths) } catch (error) { - // Si no es troben fitxers, retorna una llista buida return [] } // Only want to return blog/path and ignore root, replace is needed to work on Windows diff --git a/pages/404.tsx b/pages/404.tsx index f905faae..2c2c66cc 100644 --- a/pages/404.tsx +++ b/pages/404.tsx @@ -5,10 +5,9 @@ import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' export async function getStaticProps({ locale }) { - // Afegeix la traducció return { props: { - ...(await serverSideTranslations(locale, ['common'])), // Aquí estem assumint que el nom del teu fitxer de traducció és 'common' + ...(await serverSideTranslations(locale, ['common'])), }, } } diff --git a/pages/blog.tsx b/pages/blog.tsx index 0b90bc01..f851cf35 100644 --- a/pages/blog.tsx +++ b/pages/blog.tsx @@ -25,7 +25,7 @@ export async function getStaticProps({ locale }) { } export default function Blog({ posts, initialDisplayPosts, pagination }: BlogListProps) { - let { t } = useTranslation('common') // utilitza 'common' si els teus strings estan a common.ts o canvia-ho pel nom adequat + let { t } = useTranslation('common') return ( <> ({ params: { page: (i + 1).toString() }, diff --git a/pages/snippets/[...slug].tsx b/pages/snippets/[...slug].tsx index 130f1ae4..fa5739c5 100644 --- a/pages/snippets/[...slug].tsx +++ b/pages/snippets/[...slug].tsx @@ -29,9 +29,7 @@ export async function getStaticPaths({ locales }: { locales: string[] }) { } export async function getStaticProps({ params, locale }) { - console.log('params slug', params.slug.join('/')) let snippet = await getFileBySlug('snippets', params.slug.join('/'), locale) - let commentConfig = getCommentConfigs() return { props: { snippet, commentConfig, ...(await serverSideTranslations(locale, ['common'])) }, @@ -39,8 +37,6 @@ export async function getStaticProps({ params, locale }) { } export default function Snippet({ snippet, commentConfig }: SnippetProps) { - console.log('snippet', snippet) - let { mdxSource, frontMatter } = snippet return ( diff --git a/pages/tags/[tag].tsx b/pages/tags/[tag].tsx index eb453ce9..90ef9fb2 100644 --- a/pages/tags/[tag].tsx +++ b/pages/tags/[tag].tsx @@ -13,7 +13,6 @@ import { getCommon } from '~/libs/files' export function getStaticPaths({ locale }) { let tags = getAllTags(`${locale}/blog`) - console.log(tags) return { paths: Object.keys(tags).map((tag) => ({ params: { @@ -36,12 +35,12 @@ export async function getStaticProps({ (post) => post.draft !== true && post.tags.map((t) => kebabCase(t)).includes(params.tag) ) - // rss let root = process.cwd() - let lang_siteMetadata = getCommon(locale).siteMetadata - - console.log('lang_siteMetadata', lang_siteMetadata) - let rss = generateRss(lang_siteMetadata, filteredPosts, `tags/${params.tag}/feed.xml`) + let rss = generateRss( + getCommon(locale).siteMetadata, + filteredPosts, + `tags/${params.tag}/feed.xml` + ) let rssPath = path.join(root, 'public', 'tags', params.tag) fs.mkdirSync(rssPath, { recursive: true }) fs.writeFileSync(path.join(rssPath, 'feed.xml'), rss) @@ -56,15 +55,14 @@ export async function getStaticProps({ } export default function Tag({ posts, tag }: { posts: BlogFrontMatter[]; tag: string }) { - let { t } = useTranslation('common') // Mueve esto al principio de tu componente + let { t } = useTranslation('common') // Capitalize first letter and convert space to dash if (!tag) { - // gestionar l'error com consideris més adequat return
${t('tag.noTagsFound')}
} - let title = tag[0] + tag.split(' ').join('-').slice(1) + return ( <>