Skip to content

Commit

Permalink
chore: remove logs & clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hta218 committed Aug 13, 2023
1 parent 88fc082 commit 662c736
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 35 deletions.
3 changes: 1 addition & 2 deletions components/PostListItem.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/homepage/TypedBios.tsx
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion layouts/ListLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
Expand All @@ -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 (
<>
<div className="divide-y divide-gray-200 dark:divide-gray-700">
Expand Down
8 changes: 2 additions & 6 deletions libs/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'])),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<PageSeo
Expand Down
8 changes: 1 addition & 7 deletions pages/blog/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export async function getStaticPaths({ locales }: { locales: string[] }) {
}
}

/// getStaticProps
export async function getStaticProps({
params,
locale,
Expand All @@ -46,7 +45,6 @@ export async function getStaticProps({
let next = allPosts[postIndex - 1] || null
let page = Math.ceil((postIndex + 1) / POSTS_PER_PAGE)

// obté l'entrada de blog individual per a l'idioma correcte
let post = await getFileBySlug('blog', params.slug.join('/'), locale)
let authors = post.frontMatter.authors || ['default']
let authorDetails = await Promise.all(
Expand All @@ -57,11 +55,7 @@ export async function getStaticProps({
})
)

// Resol la ruta al fitxer .json basat en l'idioma
let lang_siteMetadata = getCommon(locale).siteMetadata

// rss
let rss = generateRss(lang_siteMetadata, allPosts)
let rss = generateRss(getCommon(locale).siteMetadata, allPosts)
fs.writeFileSync('./public/feed.xml', rss)
let commentConfig = getCommentConfigs()

Expand Down
2 changes: 1 addition & 1 deletion pages/blog/page/[page].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getStaticPaths(context: GetStaticPathsContext) {
let paths = []

for (let locale of locales) {
let totalPosts = getAllFilesFrontMatter(`${locale}/blog`) // canviat `${locale}/blog` a `blog/${locale}`
let totalPosts = getAllFilesFrontMatter(`${locale}/blog`)
let totalPages = Math.ceil(totalPosts.length / POSTS_PER_PAGE)
let localePaths = Array.from({ length: totalPages }, (_, i) => ({
params: { page: (i + 1).toString() },
Expand Down
4 changes: 0 additions & 4 deletions pages/snippets/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ 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'])) },
}
}

export default function Snippet({ snippet, commentConfig }: SnippetProps) {
console.log('snippet', snippet)

let { mdxSource, frontMatter } = snippet

return (
Expand Down
16 changes: 7 additions & 9 deletions pages/tags/[tag].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)
Expand All @@ -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 <div>${t('tag.noTagsFound')}</div>
}

let title = tag[0] + tag.split(' ').join('-').slice(1)

return (
<>
<PageSeo
Expand Down

1 comment on commit 662c736

@vercel
Copy link

@vercel vercel bot commented on 662c736 Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

leo-huynh-dot-dev – ./

leo-huynh-dot-dev-git-main-hta218.vercel.app
leohuynh.dev
leo-huynh-dot-dev-hta218.vercel.app
www.leohuynh.dev

Please sign in to comment.