Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-05-26 00:25:18 +02:00
parent fee40613f1
commit 59a0862d58
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
7 changed files with 15 additions and 37 deletions

View File

@ -150,7 +150,6 @@ module.exports = {
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": "error",
"no-debugger": "error",
"no-empty": "error",
"no-eval": "error",

View File

@ -35,6 +35,7 @@ export default class Post implements PostInterface {
public static async fetchAll(): Promise<Array<Post>> {
const files: Array<string> = ((require as any).context('../posts', true, /\.md$/)).keys()
const posts: Array<Post> = []
console.log(files)
for (const file of files) {
posts.push(new Post(file.replace('./', '')))
}
@ -43,10 +44,6 @@ export default class Post implements PostInterface {
public async fetch() {
if (!this.slug.endsWith('.md')) {
this.slug = `portfolio/${this.slug}.md`
}
const content = await import(`../posts/${this.slug}`)
const md = matter(content.default)
this.title = md.data.title
@ -55,10 +52,6 @@ export default class Post implements PostInterface {
}
public fetchSync() {
if (!this.slug.endsWith('.md')) {
this.slug = `portfolio/${this.slug}.md`
}
const content = require(`../posts/${this.slug}`)
const md = matter(content.default)
this.title = md.data.title

View File

@ -24,11 +24,16 @@ interface States {
export default class PostPage extends Component<Props, States> {
public static async getInitialProps(context: NextPageContext) {
const { slug } = context.query
if (typeof slug === 'object' || slug === '[slug]') {
const { slug, category } = context.query
if (
typeof slug === 'object' ||
slug === '[slug]' ||
typeof category === 'object' ||
category === '[category]'
) {
return {post: undefined}
}
const post = new Post(slug)
const post = new Post(`${category}/${slug}`)
await post.fetch()
return {post}
}

View File

@ -26,14 +26,15 @@ export default class Page extends Component<Props, States> {
const posts = await Post.fetchAll()
const header: Array<PostHeader> = []
const cats: Array<string> = []
posts.forEach(el => {
el.fetchSync()
for (const el of posts) {
await el.fetch()
if (!el.header) {
return
}
header.push(el.header)
cats.push(...el.header.tags || [])
})
}
header.sort((a, b) => (a.date < b.date) ? 1 : -1)
cats.sort((a, b) => (a < b) ? -1 : 1)

View File

@ -80,10 +80,11 @@ PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
if (!post.isStarted) {
await post.fetch()
}
const tags = []
if (!post.header) {
continue
}
const tags = []
for (const tg of post.header.tags || []) {
tags.push(tg.toLowerCase())
}

View File

@ -1,20 +0,0 @@
const glob = require('glob')
const fs = require('fs')
// DOMAIN NAME WITHOUT THE LAST /
const domain = "https://www.avior.me"
const files = glob.sync('./out/**/*.html')
let res = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`
for (let file of files) {
file = file.replace("./out", "").replace("index.html", "")
res += `<url><loc>${domain}${file}</loc></url>`
}
res += `</urlset>`
fs.writeFileSync('./out/sitemap.xml', res)
console.log(res)

View File

@ -110,7 +110,6 @@ $color = #6200EE
&.icon-right select, &.icon-left select
max-width 100%
input:focus:not([readonly]) + i,
select:focus:not([readonly]) + i
color $color