1
0
Fork 0

wip(org): Work on new site

This commit is contained in:
Joost De Cock 2022-05-21 19:26:43 +02:00
parent fa42e8e142
commit 623e28c675
7 changed files with 100 additions and 8 deletions

View file

@ -0,0 +1,3 @@
import i18n from '../freesewing.shared/config/i18n.config.mjs'
export default i18n()

View file

@ -0,0 +1,13 @@
// See: https://github.com/isaachinman/next-i18next
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'de', 'es', 'fr', 'nl'],
defaultNS: 'common',
},
interpolation: {
prefix: '{',
suffix: '}',
},
localeStructure: '{lng}/{ns}',
}

View file

@ -1,3 +1,38 @@
import configBuilder from '../freesewing.shared/config/next.mjs'
import path from 'path'
import { readdirSync } from 'fs'
import i18nConfig from './next-i18next.config.js'
export default configBuilder('dev')
const getDirectories = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
const pkgs = getDirectories(path.resolve(`../`))
const config = {
experimental: {
externalDir: true,
},
i18n: i18nConfig.i18n,
pageExtensions: [ 'js' ],
webpack: (config, options) => {
// YAML support
config.module.rules.push({
test: /\.ya?ml$/,
type: 'json',
use: 'yaml-loader'
})
// Aliases
config.resolve.alias.shared = path.resolve('../freesewing.shared/')
config.resolve.alias.site = path.resolve(`.`)
config.resolve.alias.pkgs = path.resolve(`../`)
// This forces webpack to load the code from source, rather than compiled bundle
for (const pkg of pkgs) {
config.resolve.alias[`@freesewing/${pkg}$`] = path.resolve(`../${pkg}/src/index.js`)
}
return config
}
}
export default config

View file

@ -1,5 +1,6 @@
import 'shared/styles/globals.css'
import { appWithTranslation } from 'next-i18next'
const FreeSewingDev = ({ Component, pageProps }) => <Component {...pageProps} />
const FreeSewingOrg = ({ Component, pageProps }) => <Component {...pageProps} />
export default FreeSewingDev
export default appWithTranslation(FreeSewingOrg)

View file

@ -0,0 +1,23 @@
/* This is the recommended way to load a font */
import Document, { Html, Head, Main, NextScript } from 'next/document'
class FsDocument extends Document {
render() {
return (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap"
rel="stylesheet"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default FsDocument

View file

@ -9,6 +9,18 @@ import remarkFrontmatterExtractor from 'remark-extract-frontmatter'
import { readSync } from 'to-vfile'
import yaml from 'js-yaml'
/*
* There's an issue in crowdin where it changes the frontmatter marker:
* ---
* into this:
* - - -
* which breaks stuff. So this method takes the input and replaces all
* - - - with ---
*/
const fixCrowdinBugs = md => {
md.value = md.value.split("- - -\n").join("---\n")
return md
}
/*
* Helper method to get a list of MDX files in a folder.
@ -62,12 +74,11 @@ const mdxMetaInfo = async file => {
let result
try {
result = await unified()
//.use(remarkMdx)
.use(remarkParser)
.use(remarkCompiler)
.use(remarkFrontmatter)
.use(remarkFrontmatterExtractor, { yaml: yaml.load })
.process(readSync(file))
.process(fixCrowdinBugs(readSync(file, { encoding: 'utf-8' })))
}
catch (err) {
console.log(err)
@ -112,8 +123,13 @@ export const prebuildMdx = async(site) => {
: meta.data.title
}
} else {
console.log(`[${lang}] Failed to extract meta info from: ${slug}`)
if (meta.messages.length > 0) console.log(meta.messages)
if (pages.en[slug]) {
console.log(`l Falling back to EN metadata for ${slug}`)
pages[lang][slug] = pages.en[slug]
} else {
console.log(`❌ [${lang}] Failed to extract meta info from: ${slug}`)
if (meta.messages.length > 0) console.log(meta.messages)
}
}
}
}

View file

@ -80,6 +80,7 @@ export const prebuildStrapi = async(site) => {
posts[lang][type] = await getPosts(type, site, lang)
// Extract list of authors
for (const [slug, post] of Object.entries(posts[lang][type])) {
if (!post.author?.slug) console.log(post)
authors[type][post.author.slug] = post.author
posts[lang][type][slug].author = post.author.slug
}