From 7f6eac41024cb08a5be49be256efa5ecfd2f64d8 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 20 May 2024 23:21:44 +0200 Subject: [PATCH] fix all build error --- .../post/astrowind-template-in-depth.mdx | 4 +- .../post/markdown-elements-demo-post.mdx | 2 +- front/src/pages/maps.astro | 11 +- front/src/pages/rss.xml.ts | 4 +- front/src/utils/blog.ts | 415 +++++++++--------- front/src/utils/permalinks.ts | 201 ++++----- front/tsconfig.json | 3 +- .../vendor/integration/utils/configBuilder.ts | 301 ++++++------- 8 files changed, 476 insertions(+), 465 deletions(-) diff --git a/front/src/content/post/astrowind-template-in-depth.mdx b/front/src/content/post/astrowind-template-in-depth.mdx index e7c4dd8..36a0ca4 100644 --- a/front/src/content/post/astrowind-template-in-depth.mdx +++ b/front/src/content/post/astrowind-template-in-depth.mdx @@ -12,8 +12,8 @@ metadata: canonical: https://astrowind.vercel.app/astrowind-template-in-depth --- -import DListItem from '~/components/ui/DListItem.astro'; -import ToggleTheme from '~/components/common/ToggleTheme.astro'; +import DListItem from 'components/ui/DListItem.astro'; +import ToggleTheme from 'components/common/ToggleTheme.astro'; ## Overview diff --git a/front/src/content/post/markdown-elements-demo-post.mdx b/front/src/content/post/markdown-elements-demo-post.mdx index a55669d..8eddc3b 100644 --- a/front/src/content/post/markdown-elements-demo-post.mdx +++ b/front/src/content/post/markdown-elements-demo-post.mdx @@ -8,7 +8,7 @@ tags: - Astro --- -import Logo from '~/components/Logo.astro'; +import Logo from 'components/Logo.astro'; import { YouTube, Tweet, Vimeo } from 'astro-embed'; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. diff --git a/front/src/pages/maps.astro b/front/src/pages/maps.astro index f1e59aa..c543c60 100644 --- a/front/src/pages/maps.astro +++ b/front/src/pages/maps.astro @@ -1,9 +1,14 @@ --- -import Layout from 'layouts/Layout.astro'; +import Layout from 'layouts/PageLayout.astro'; import 'leaflet/dist/leaflet.css' + +const metadata = { + title: 'Maps', + ignoreTitleTemplate: true, +}; --- - +
@@ -23,4 +28,4 @@ import 'leaflet/dist/leaflet.css' attribution: '© OpenStreetMap' }).addTo(map); var marker = L.marker([51.5, -0.09]).addTo(map); - \ No newline at end of file + diff --git a/front/src/pages/rss.xml.ts b/front/src/pages/rss.xml.ts index f8831b7..c40200b 100644 --- a/front/src/pages/rss.xml.ts +++ b/front/src/pages/rss.xml.ts @@ -1,8 +1,8 @@ import { getRssString } from '@astrojs/rss'; import { SITE, METADATA, APP_BLOG } from 'astrowind:config'; -import { fetchPosts } from '~/utils/blog'; -import { getPermalink } from '~/utils/permalinks'; +import { fetchPosts } from 'utils/blog'; +import { getPermalink } from 'utils/permalinks'; export const GET = async () => { if (!APP_BLOG.isEnabled) { diff --git a/front/src/utils/blog.ts b/front/src/utils/blog.ts index dec56f6..40ef2eb 100644 --- a/front/src/utils/blog.ts +++ b/front/src/utils/blog.ts @@ -1,278 +1,281 @@ -import type { PaginateFunction } from 'astro'; -import { getCollection } from 'astro:content'; -import type { CollectionEntry } from 'astro:content'; -import type { Post } from '~/types'; -import { APP_BLOG } from 'astrowind:config'; -import { cleanSlug, trimSlash, BLOG_BASE, POST_PERMALINK_PATTERN, CATEGORY_BASE, TAG_BASE } from './permalinks'; +/* eslint-disable @typescript-eslint/no-unused-expressions */ +/* eslint-disable id-length */ +import type { PaginateFunction } from 'astro' +import { getCollection } from 'astro:content' +import type { CollectionEntry } from 'astro:content' +import type { Post } from 'types' +import { APP_BLOG } from 'astrowind:config' +import { cleanSlug, trimSlash, BLOG_BASE, POST_PERMALINK_PATTERN, CATEGORY_BASE, TAG_BASE } from './permalinks' const generatePermalink = async ({ - id, - slug, - publishDate, - category, + id, + slug, + publishDate, + category, }: { - id: string; - slug: string; - publishDate: Date; - category: string | undefined; + id: string + slug: string + publishDate: Date + category: string | undefined }) => { - const year = String(publishDate.getFullYear()).padStart(4, '0'); - const month = String(publishDate.getMonth() + 1).padStart(2, '0'); - const day = String(publishDate.getDate()).padStart(2, '0'); - const hour = String(publishDate.getHours()).padStart(2, '0'); - const minute = String(publishDate.getMinutes()).padStart(2, '0'); - const second = String(publishDate.getSeconds()).padStart(2, '0'); + const year = String(publishDate.getFullYear()).padStart(4, '0') + const month = String(publishDate.getMonth() + 1).padStart(2, '0') + const day = String(publishDate.getDate()).padStart(2, '0') + const hour = String(publishDate.getHours()).padStart(2, '0') + const minute = String(publishDate.getMinutes()).padStart(2, '0') + const second = String(publishDate.getSeconds()).padStart(2, '0') - const permalink = POST_PERMALINK_PATTERN.replace('%slug%', slug) - .replace('%id%', id) - .replace('%category%', category || '') - .replace('%year%', year) - .replace('%month%', month) - .replace('%day%', day) - .replace('%hour%', hour) - .replace('%minute%', minute) - .replace('%second%', second); + const permalink = POST_PERMALINK_PATTERN.replace('%slug%', slug) + .replace('%id%', id) + .replace('%category%', category || '') + .replace('%year%', year) + .replace('%month%', month) + .replace('%day%', day) + .replace('%hour%', hour) + .replace('%minute%', minute) + .replace('%second%', second) - return permalink - .split('/') - .map((el) => trimSlash(el)) - .filter((el) => !!el) - .join('/'); -}; + return permalink + .split('/') + .map((el) => trimSlash(el)) + .filter((el) => !!el) + .join('/') +} const getNormalizedPost = async (post: CollectionEntry<'post'>): Promise => { - const { id, slug: rawSlug = '', data } = post; - const { Content, remarkPluginFrontmatter } = await post.render(); + const { id, slug: rawSlug = '', data } = post + const { Content, remarkPluginFrontmatter } = await post.render() - const { - publishDate: rawPublishDate = new Date(), - updateDate: rawUpdateDate, - title, - excerpt, - image, - tags: rawTags = [], - category: rawCategory, - author, - draft = false, - metadata = {}, - } = data; + const { + publishDate: rawPublishDate = new Date(), + updateDate: rawUpdateDate, + title, + excerpt, + image, + tags: rawTags = [], + category: rawCategory, + author, + draft = false, + metadata = {}, + } = data - const slug = cleanSlug(rawSlug); // cleanSlug(rawSlug.split('/').pop()); - const publishDate = new Date(rawPublishDate); - const updateDate = rawUpdateDate ? new Date(rawUpdateDate) : undefined; + const slug = cleanSlug(rawSlug) // cleanSlug(rawSlug.split('/').pop()) + const publishDate = new Date(rawPublishDate) + const updateDate = rawUpdateDate ? new Date(rawUpdateDate) : undefined - const category = rawCategory - ? { - slug: cleanSlug(rawCategory), - title: rawCategory, - } - : undefined; + const category = rawCategory + ? { + slug: cleanSlug(rawCategory), + title: rawCategory, + } + : undefined - const tags = rawTags.map((tag: string) => ({ - slug: cleanSlug(tag), - title: tag, - })); + const tags = rawTags.map((tag: string) => ({ + slug: cleanSlug(tag), + title: tag, + })) - return { - id: id, - slug: slug, - permalink: await generatePermalink({ id, slug, publishDate, category: category?.slug }), + return { + id: id, + slug: slug, + permalink: await generatePermalink({ id, slug, publishDate, category: category?.slug }), - publishDate: publishDate, - updateDate: updateDate, + publishDate: publishDate, + updateDate: updateDate, - title: title, - excerpt: excerpt, - image: image, + title: title, + excerpt: excerpt, + image: image, - category: category, - tags: tags, - author: author, + category: category, + tags: tags, + author: author, - draft: draft, + draft: draft, - metadata, + metadata, - Content: Content, - // or 'content' in case you consume from API + Content: Content, + // or 'content' in case you consume from API - readingTime: remarkPluginFrontmatter?.readingTime, - }; -}; + readingTime: remarkPluginFrontmatter?.readingTime, + } +} -const load = async function (): Promise> { - const posts = await getCollection('post'); - const normalizedPosts = posts.map(async (post) => await getNormalizedPost(post)); +const load = async function(): Promise> { + const posts = await getCollection('post') + const normalizedPosts = posts.map(async (post) => await getNormalizedPost(post)) - const results = (await Promise.all(normalizedPosts)) - .sort((a, b) => b.publishDate.valueOf() - a.publishDate.valueOf()) - .filter((post) => !post.draft); + const results = (await Promise.all(normalizedPosts)) + .sort((a, b) => b.publishDate.valueOf() - a.publishDate.valueOf()) + .filter((post) => !post.draft) - return results; -}; + return results +} -let _posts: Array; +let _posts: Array /** */ -export const isBlogEnabled = APP_BLOG.isEnabled; -export const isRelatedPostsEnabled = APP_BLOG.isRelatedPostsEnabled; -export const isBlogListRouteEnabled = APP_BLOG.list.isEnabled; -export const isBlogPostRouteEnabled = APP_BLOG.post.isEnabled; -export const isBlogCategoryRouteEnabled = APP_BLOG.category.isEnabled; -export const isBlogTagRouteEnabled = APP_BLOG.tag.isEnabled; +export const isBlogEnabled = APP_BLOG.isEnabled +export const isRelatedPostsEnabled = APP_BLOG.isRelatedPostsEnabled +export const isBlogListRouteEnabled = APP_BLOG.list.isEnabled +export const isBlogPostRouteEnabled = APP_BLOG.post.isEnabled +export const isBlogCategoryRouteEnabled = APP_BLOG.category.isEnabled +export const isBlogTagRouteEnabled = APP_BLOG.tag.isEnabled -export const blogListRobots = APP_BLOG.list.robots; -export const blogPostRobots = APP_BLOG.post.robots; -export const blogCategoryRobots = APP_BLOG.category.robots; -export const blogTagRobots = APP_BLOG.tag.robots; +export const blogListRobots = APP_BLOG.list.robots +export const blogPostRobots = APP_BLOG.post.robots +export const blogCategoryRobots = APP_BLOG.category.robots +export const blogTagRobots = APP_BLOG.tag.robots -export const blogPostsPerPage = APP_BLOG?.postsPerPage; +export const blogPostsPerPage = APP_BLOG?.postsPerPage /** */ export const fetchPosts = async (): Promise> => { - if (!_posts) { - _posts = await load(); - } + if (!_posts) { + // eslint-disable-next-line require-atomic-updates + _posts = await load() + } - return _posts; -}; + return _posts +} /** */ export const findPostsBySlugs = async (slugs: Array): Promise> => { - if (!Array.isArray(slugs)) return []; + if (!Array.isArray(slugs)) {return []} - const posts = await fetchPosts(); + const posts = await fetchPosts() - return slugs.reduce(function (r: Array, slug: string) { - posts.some(function (post: Post) { - return slug === post.slug && r.push(post); - }); - return r; - }, []); -}; + return slugs.reduce(function(r: Array, slug: string) { + posts.some(function(post: Post) { + return slug === post.slug && r.push(post) + }) + return r + }, []) +} /** */ export const findPostsByIds = async (ids: Array): Promise> => { - if (!Array.isArray(ids)) return []; + if (!Array.isArray(ids)) {return []} - const posts = await fetchPosts(); + const posts = await fetchPosts() - return ids.reduce(function (r: Array, id: string) { - posts.some(function (post: Post) { - return id === post.id && r.push(post); - }); - return r; - }, []); -}; + return ids.reduce(function(r: Array, id: string) { + posts.some(function(post: Post) { + return id === post.id && r.push(post) + }) + return r + }, []) +} /** */ export const findLatestPosts = async ({ count }: { count?: number }): Promise> => { - const _count = count || 4; - const posts = await fetchPosts(); + const _count = count || 4 + const posts = await fetchPosts() - return posts ? posts.slice(0, _count) : []; -}; + return posts ? posts.slice(0, _count) : [] +} /** */ export const getStaticPathsBlogList = async ({ paginate }: { paginate: PaginateFunction }) => { - if (!isBlogEnabled || !isBlogListRouteEnabled) return []; - return paginate(await fetchPosts(), { - params: { blog: BLOG_BASE || undefined }, - pageSize: blogPostsPerPage, - }); -}; + if (!isBlogEnabled || !isBlogListRouteEnabled) {return []} + return paginate(await fetchPosts(), { + params: { blog: BLOG_BASE || undefined }, + pageSize: blogPostsPerPage, + }) +} /** */ export const getStaticPathsBlogPost = async () => { - if (!isBlogEnabled || !isBlogPostRouteEnabled) return []; - return (await fetchPosts()).flatMap((post) => ({ - params: { - blog: post.permalink, - }, - props: { post }, - })); -}; + if (!isBlogEnabled || !isBlogPostRouteEnabled) {return []} + return (await fetchPosts()).flatMap((post) => ({ + params: { + blog: post.permalink, + }, + props: { post }, + })) +} /** */ export const getStaticPathsBlogCategory = async ({ paginate }: { paginate: PaginateFunction }) => { - if (!isBlogEnabled || !isBlogCategoryRouteEnabled) return []; + if (!isBlogEnabled || !isBlogCategoryRouteEnabled) {return []} - const posts = await fetchPosts(); - const categories = {}; - posts.map((post) => { - post.category?.slug && (categories[post.category?.slug] = post.category); - }); + const posts = await fetchPosts() + const categories = {} + posts.map((post) => { + post.category?.slug && (categories[post.category?.slug] = post.category) + }) - return Array.from(Object.keys(categories)).flatMap((categorySlug) => - paginate( - posts.filter((post) => post.category?.slug && categorySlug === post.category?.slug), - { - params: { category: categorySlug, blog: CATEGORY_BASE || undefined }, - pageSize: blogPostsPerPage, - props: { category: categories[categorySlug] }, - } - ) - ); -}; + return Array.from(Object.keys(categories)).flatMap((categorySlug) => + paginate( + posts.filter((post) => post.category?.slug && categorySlug === post.category?.slug), + { + params: { category: categorySlug, blog: CATEGORY_BASE || undefined }, + pageSize: blogPostsPerPage, + props: { category: categories[categorySlug] }, + } + ) + ) +} /** */ export const getStaticPathsBlogTag = async ({ paginate }: { paginate: PaginateFunction }) => { - if (!isBlogEnabled || !isBlogTagRouteEnabled) return []; + if (!isBlogEnabled || !isBlogTagRouteEnabled) {return []} - const posts = await fetchPosts(); - const tags = {}; - posts.map((post) => { - Array.isArray(post.tags) && - post.tags.map((tag) => { - tags[tag?.slug] = tag; - }); - }); + const posts = await fetchPosts() + const tags = {} + posts.map((post) => { + Array.isArray(post.tags) && + post.tags.map((tag) => { + tags[tag?.slug] = tag + }) + }) - return Array.from(Object.keys(tags)).flatMap((tagSlug) => - paginate( - posts.filter((post) => Array.isArray(post.tags) && post.tags.find((elem) => elem.slug === tagSlug)), - { - params: { tag: tagSlug, blog: TAG_BASE || undefined }, - pageSize: blogPostsPerPage, - props: { tag: tags[tagSlug] }, - } - ) - ); -}; + return Array.from(Object.keys(tags)).flatMap((tagSlug) => + paginate( + posts.filter((post) => Array.isArray(post.tags) && post.tags.find((elem) => elem.slug === tagSlug)), + { + params: { tag: tagSlug, blog: TAG_BASE || undefined }, + pageSize: blogPostsPerPage, + props: { tag: tags[tagSlug] }, + } + ) + ) +} /** */ -export async function getRelatedPosts(originalPost: Post, maxResults: number = 4): Promise { - const allPosts = await fetchPosts(); - const originalTagsSet = new Set(originalPost.tags ? originalPost.tags.map((tag) => tag.slug) : []); +export async function getRelatedPosts(originalPost: Post, maxResults = 4): Promise> { + const allPosts = await fetchPosts() + const originalTagsSet = new Set(originalPost.tags ? originalPost.tags.map((tag) => tag.slug) : []) - const postsWithScores = allPosts.reduce((acc: { post: Post; score: number }[], iteratedPost: Post) => { - if (iteratedPost.slug === originalPost.slug) return acc; + const postsWithScores = allPosts.reduce((acc: Array<{ post: Post, score: number }>, iteratedPost: Post) => { + if (iteratedPost.slug === originalPost.slug) {return acc} - let score = 0; - if (iteratedPost.category && originalPost.category && iteratedPost.category.slug === originalPost.category.slug) { - score += 5; - } + let score = 0 + if (iteratedPost.category && originalPost.category && iteratedPost.category.slug === originalPost.category.slug) { + score += 5 + } - if (iteratedPost.tags) { - iteratedPost.tags.forEach((tag) => { - if (originalTagsSet.has(tag.slug)) { - score += 1; - } - }); - } + if (iteratedPost.tags) { + iteratedPost.tags.forEach((tag) => { + if (originalTagsSet.has(tag.slug)) { + score += 1 + } + }) + } - acc.push({ post: iteratedPost, score }); - return acc; - }, []); + acc.push({ post: iteratedPost, score }) + return acc + }, []) - postsWithScores.sort((a, b) => b.score - a.score); + postsWithScores.sort((a, b) => b.score - a.score) - const selectedPosts: Post[] = []; - let i = 0; - while (selectedPosts.length < maxResults && i < postsWithScores.length) { - selectedPosts.push(postsWithScores[i].post); - i++; - } + const selectedPosts: Array = [] + let i = 0 + while (selectedPosts.length < maxResults && i < postsWithScores.length) { + selectedPosts.push(postsWithScores[i].post) + i++ + } - return selectedPosts; + return selectedPosts } diff --git a/front/src/utils/permalinks.ts b/front/src/utils/permalinks.ts index 4e3078d..1f038b3 100644 --- a/front/src/utils/permalinks.ts +++ b/front/src/utils/permalinks.ts @@ -1,134 +1,135 @@ -import slugify from 'limax'; +/* eslint-disable max-depth */ +/* eslint-disable complexity */ +import slugify from 'limax' -import { SITE, APP_BLOG } from 'astrowind:config'; +import { SITE, APP_BLOG } from 'astrowind:config' -import { trim } from '~/utils/utils'; +import { trim } from 'utils/utils' -export const trimSlash = (s: string) => trim(trim(s, '/')); -const createPath = (...params: string[]) => { - const paths = params - .map((el) => trimSlash(el)) - .filter((el) => !!el) - .join('/'); - return '/' + paths + (SITE.trailingSlash && paths ? '/' : ''); -}; +export const trimSlash = (s: string) => trim(trim(s, '/')) +const createPath = (...params: Array) => { + const paths = params + .map((el) => trimSlash(el)) + .filter((el) => !!el) + .join('/') + return '/' + paths + (SITE.trailingSlash && paths ? '/' : '') +} -const BASE_PATHNAME = SITE.base || '/'; +const BASE_PATHNAME = SITE.base || '/' export const cleanSlug = (text = '') => - trimSlash(text) - .split('/') - .map((slug) => slugify(slug)) - .join('/'); + trimSlash(text) + .split('/') + .map((slug) => slugify(slug)) + .join('/') -export const BLOG_BASE = cleanSlug(APP_BLOG?.list?.pathname); -export const CATEGORY_BASE = cleanSlug(APP_BLOG?.category?.pathname); -export const TAG_BASE = cleanSlug(APP_BLOG?.tag?.pathname) || 'tag'; +export const BLOG_BASE = cleanSlug(APP_BLOG?.list?.pathname) +export const CATEGORY_BASE = cleanSlug(APP_BLOG?.category?.pathname) +export const TAG_BASE = cleanSlug(APP_BLOG?.tag?.pathname) || 'tag' -export const POST_PERMALINK_PATTERN = trimSlash(APP_BLOG?.post?.permalink || `${BLOG_BASE}/%slug%`); +export const POST_PERMALINK_PATTERN = trimSlash(APP_BLOG?.post?.permalink || `${BLOG_BASE}/%slug%`) /** */ export const getCanonical = (path = ''): string | URL => { - const url = String(new URL(path, SITE.site)); - if (SITE.trailingSlash == false && path && url.endsWith('/')) { - return url.slice(0, -1); - } else if (SITE.trailingSlash == true && path && !url.endsWith('/')) { - return url + '/'; - } - return url; -}; + const url = String(new URL(path, SITE.site)) + if (SITE.trailingSlash === false && path && url.endsWith('/')) { + return url.slice(0, -1) + } else if (SITE.trailingSlash == true && path && !url.endsWith('/')) { + return url + '/' + } + return url +} -/** */ export const getPermalink = (slug = '', type = 'page'): string => { - let permalink: string; + let permalink: string - if ( - slug.startsWith('https://') || - slug.startsWith('http://') || - slug.startsWith('://') || - slug.startsWith('#') || - slug.startsWith('javascript:') - ) { - return slug; - } + if ( + slug.startsWith('https://') || + slug.startsWith('http://') || + slug.startsWith('://') || + slug.startsWith('#') || + slug.startsWith('javascript:') + ) { + return slug + } - switch (type) { - case 'home': - permalink = getHomePermalink(); - break; + switch (type) { + case 'home': + permalink = getHomePermalink() + break - case 'blog': - permalink = getBlogPermalink(); - break; + case 'blog': + permalink = getBlogPermalink() + break - case 'asset': - permalink = getAsset(slug); - break; + case 'asset': + permalink = getAsset(slug) + break - case 'category': - permalink = createPath(CATEGORY_BASE, trimSlash(slug)); - break; + case 'category': + permalink = createPath(CATEGORY_BASE, trimSlash(slug)) + break - case 'tag': - permalink = createPath(TAG_BASE, trimSlash(slug)); - break; + case 'tag': + permalink = createPath(TAG_BASE, trimSlash(slug)) + break - case 'post': - permalink = createPath(trimSlash(slug)); - break; + case 'post': + permalink = createPath(trimSlash(slug)) + break - case 'page': - default: - permalink = createPath(slug); - break; - } + case 'page': + default: + permalink = createPath(slug) + break + } - return definitivePermalink(permalink); -}; + return definitivePermalink(permalink) +} /** */ -export const getHomePermalink = (): string => getPermalink('/'); +export const getHomePermalink = (): string => getPermalink('/') /** */ -export const getBlogPermalink = (): string => getPermalink(BLOG_BASE); +export const getBlogPermalink = (): string => getPermalink(BLOG_BASE) /** */ export const getAsset = (path: string): string => - '/' + - [BASE_PATHNAME, path] - .map((el) => trimSlash(el)) - .filter((el) => !!el) - .join('/'); + '/' + + [BASE_PATHNAME, path] + .map((el) => trimSlash(el)) + .filter((el) => !!el) + .join('/') /** */ -const definitivePermalink = (permalink: string): string => createPath(BASE_PATHNAME, permalink); +const definitivePermalink = (permalink: string): string => createPath(BASE_PATHNAME, permalink) /** */ export const applyGetPermalinks = (menu: object = {}) => { - if (Array.isArray(menu)) { - return menu.map((item) => applyGetPermalinks(item)); - } else if (typeof menu === 'object' && menu !== null) { - const obj = {}; - for (const key in menu) { - if (key === 'href') { - if (typeof menu[key] === 'string') { - obj[key] = getPermalink(menu[key]); - } else if (typeof menu[key] === 'object') { - if (menu[key].type === 'home') { - obj[key] = getHomePermalink(); - } else if (menu[key].type === 'blog') { - obj[key] = getBlogPermalink(); - } else if (menu[key].type === 'asset') { - obj[key] = getAsset(menu[key].url); - } else if (menu[key].url) { - obj[key] = getPermalink(menu[key].url, menu[key].type); - } - } - } else { - obj[key] = applyGetPermalinks(menu[key]); - } - } - return obj; - } - return menu; -}; + if (Array.isArray(menu)) { + return menu.map((item) => applyGetPermalinks(item)) + } else if (typeof menu === 'object' && menu !== null) { + const obj = {} + for (const key in menu) { + if (key === 'href') { + if (typeof menu[key] === 'string') { + obj[key] = getPermalink(menu[key]) + } else if (typeof menu[key] === 'object') { + if (menu[key].type === 'home') { + obj[key] = getHomePermalink() + } else if (menu[key].type === 'blog') { + obj[key] = getBlogPermalink() + } else if (menu[key].type === 'asset') { + obj[key] = getAsset(menu[key].url) + } else if (menu[key].url) { + obj[key] = getPermalink(menu[key].url, menu[key].type) + } + } + } else { + obj[key] = applyGetPermalinks(menu[key]) + } + } + return obj + } + return menu +} diff --git a/front/tsconfig.json b/front/tsconfig.json index d2b6ad7..76a07fc 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -4,7 +4,8 @@ "allowJs": true, "baseUrl": "src", // hide an issue with typescript - "noUnusedLocals": false + "noUnusedLocals": false, + "noImplicitAny": false, }, "ts-node": { "esm": true diff --git a/front/vendor/integration/utils/configBuilder.ts b/front/vendor/integration/utils/configBuilder.ts index f4b5f6d..b274ef0 100644 --- a/front/vendor/integration/utils/configBuilder.ts +++ b/front/vendor/integration/utils/configBuilder.ts @@ -1,201 +1,202 @@ -import merge from 'lodash.merge'; +/* eslint-disable @typescript-eslint/no-empty-interface */ +import merge from 'lodash.merge' -import type { MetaData } from '~/types'; +import type { MetaData } from 'types' -type Config = { - site?: SiteConfig; - metadata?: MetaDataConfig; - i18n?: I18NConfig; +interface Config { + site?: SiteConfig + metadata?: MetaDataConfig + i18n?: I18NConfig apps?: { - blog?: AppBlogConfig; - }; - ui?: unknown; - analytics?: unknown; -}; + blog?: AppBlogConfig + } + ui?: unknown + analytics?: unknown +} export interface SiteConfig { - name: string; - site?: string; - base?: string; - trailingSlash?: boolean; - googleSiteVerificationId?: string; + name: string + site?: string + base?: string + trailingSlash?: boolean + googleSiteVerificationId?: string } export interface MetaDataConfig extends Omit { title?: { - default: string; - template: string; - }; + default: string + template: string + } } export interface I18NConfig { - language: string; - textDirection: string; - dateFormatter?: Intl.DateTimeFormat; + language: string + textDirection: string + dateFormatter?: Intl.DateTimeFormat } export interface AppBlogConfig { - isEnabled: boolean; - postsPerPage: number; - isRelatedPostsEnabled: boolean; - relatedPostsCount: number; + isEnabled: boolean + postsPerPage: number + isRelatedPostsEnabled: boolean + relatedPostsCount: number post: { - isEnabled: boolean; - permalink: string; + isEnabled: boolean + permalink: string robots: { - index: boolean; - follow: boolean; - }; - }; + index: boolean + follow: boolean + } + } list: { - isEnabled: boolean; - pathname: string; + isEnabled: boolean + pathname: string robots: { - index: boolean; - follow: boolean; - }; - }; + index: boolean + follow: boolean + } + } category: { - isEnabled: boolean; - pathname: string; + isEnabled: boolean + pathname: string robots: { - index: boolean; - follow: boolean; - }; - }; + index: boolean + follow: boolean + } + } tag: { - isEnabled: boolean; - pathname: string; + isEnabled: boolean + pathname: string robots: { - index: boolean; - follow: boolean; - }; - }; + index: boolean + follow: boolean + } + } } export interface AnalyticsConfig { vendors: { googleAnalytics: { - id?: string; - partytown?: boolean; - }; - }; + id?: string + partytown?: boolean + } + } } export interface UIConfig {} -const DEFAULT_SITE_NAME = 'Website'; +const DEFAULT_SITE_NAME = 'Website' const getSite = (config: Config) => { - const _default = { - name: DEFAULT_SITE_NAME, - site: undefined, - base: '/', - trailingSlash: false, + const _default = { + name: DEFAULT_SITE_NAME, + site: undefined, + base: '/', + trailingSlash: false, - googleSiteVerificationId: '', - }; + googleSiteVerificationId: '', + } - return merge({}, _default, config?.site ?? {}) as SiteConfig; -}; + return merge({}, _default, config?.site ?? {}) as SiteConfig +} const getMetadata = (config: Config) => { - const siteConfig = getSite(config); + const siteConfig = getSite(config) - const _default = { - title: { - default: siteConfig?.name || DEFAULT_SITE_NAME, - template: '%s', - }, - description: '', - robots: { - index: false, - follow: false, - }, - openGraph: { - type: 'website', - }, - }; + const _default = { + title: { + default: siteConfig?.name || DEFAULT_SITE_NAME, + template: '%s', + }, + description: '', + robots: { + index: false, + follow: false, + }, + openGraph: { + type: 'website', + }, + } - return merge({}, _default, config?.metadata ?? {}) as MetaDataConfig; -}; + return merge({}, _default, config?.metadata ?? {}) as MetaDataConfig +} const getI18N = (config: Config) => { - const _default = { - language: 'en', - textDirection: 'ltr', - }; + const _default = { + language: 'en', + textDirection: 'ltr', + } - const value = merge({}, _default, config?.i18n ?? {}); + const value = merge({}, _default, config?.i18n ?? {}) - return value as I18NConfig; -}; + return value as I18NConfig +} const getAppBlog = (config: Config) => { - const _default = { - isEnabled: false, - postsPerPage: 6, - isRelatedPostsEnabled: false, - relatedPostsCount: 4, - post: { - isEnabled: true, - permalink: '/blog/%slug%', - robots: { - index: true, - follow: true, - }, - }, - list: { - isEnabled: true, - pathname: 'blog', - robots: { - index: true, - follow: true, - }, - }, - category: { - isEnabled: true, - pathname: 'category', - robots: { - index: true, - follow: true, - }, - }, - tag: { - isEnabled: true, - pathname: 'tag', - robots: { - index: false, - follow: true, - }, - }, - }; + const _default = { + isEnabled: false, + postsPerPage: 6, + isRelatedPostsEnabled: false, + relatedPostsCount: 4, + post: { + isEnabled: true, + permalink: '/blog/%slug%', + robots: { + index: true, + follow: true, + }, + }, + list: { + isEnabled: true, + pathname: 'blog', + robots: { + index: true, + follow: true, + }, + }, + category: { + isEnabled: true, + pathname: 'category', + robots: { + index: true, + follow: true, + }, + }, + tag: { + isEnabled: true, + pathname: 'tag', + robots: { + index: false, + follow: true, + }, + }, + } - return merge({}, _default, config?.apps?.blog ?? {}) as AppBlogConfig; -}; + return merge({}, _default, config?.apps?.blog ?? {}) as AppBlogConfig +} const getUI = (config: Config) => { - const _default = { - theme: 'system', - }; + const _default = { + theme: 'system', + } - return merge({}, _default, config?.ui ?? {}); -}; + return merge({}, _default, config?.ui ?? {}) +} const getAnalytics = (config: Config) => { - const _default = { - vendors: { - googleAnalytics: { - id: undefined, - partytown: true, - }, - }, - }; + const _default = { + vendors: { + googleAnalytics: { + id: undefined, + partytown: true, + }, + }, + } - return merge({}, _default, config?.analytics ?? {}) as AnalyticsConfig; -}; + return merge({}, _default, config?.analytics ?? {}) as AnalyticsConfig +} export default (config: Config) => ({ - SITE: getSite(config), - I18N: getI18N(config), - METADATA: getMetadata(config), - APP_BLOG: getAppBlog(config), - UI: getUI(config), - ANALYTICS: getAnalytics(config), -}); + SITE: getSite(config), + I18N: getI18N(config), + METADATA: getMetadata(config), + APP_BLOG: getAppBlog(config), + UI: getUI(config), + ANALYTICS: getAnalytics(config), +})