From 59a0862d58e69d86ed5cb2c6b51edcb1ce16240a Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 26 May 2020 00:25:18 +0200 Subject: [PATCH] Updated Signed-off-by: Avior --- .eslintrc.js | 1 - components/Post.ts | 9 +-------- pages/[category]/[slug].tsx | 11 ++++++++--- pages/index.tsx | 7 ++++--- pages/tag/[tag].tsx | 3 ++- scripts/generateSitemap.js | 20 -------------------- styl/include/_input.styl | 1 - 7 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 scripts/generateSitemap.js diff --git a/.eslintrc.js b/.eslintrc.js index 600024d..2a3b89f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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", diff --git a/components/Post.ts b/components/Post.ts index 7664859..2a31625 100644 --- a/components/Post.ts +++ b/components/Post.ts @@ -35,6 +35,7 @@ export default class Post implements PostInterface { public static async fetchAll(): Promise> { const files: Array = ((require as any).context('../posts', true, /\.md$/)).keys() const posts: Array = [] + 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 diff --git a/pages/[category]/[slug].tsx b/pages/[category]/[slug].tsx index a02e379..3311de0 100644 --- a/pages/[category]/[slug].tsx +++ b/pages/[category]/[slug].tsx @@ -24,11 +24,16 @@ interface States { export default class PostPage extends Component { 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} } diff --git a/pages/index.tsx b/pages/index.tsx index ff07f09..115dd1d 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -26,14 +26,15 @@ export default class Page extends Component { const posts = await Post.fetchAll() const header: Array = [] const cats: Array = [] - 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) diff --git a/pages/tag/[tag].tsx b/pages/tag/[tag].tsx index 06d6756..148d22f 100644 --- a/pages/tag/[tag].tsx +++ b/pages/tag/[tag].tsx @@ -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()) } diff --git a/scripts/generateSitemap.js b/scripts/generateSitemap.js deleted file mode 100644 index 8c00413..0000000 --- a/scripts/generateSitemap.js +++ /dev/null @@ -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 = `` - -for (let file of files) { - file = file.replace("./out", "").replace("index.html", "") - res += `${domain}${file}` -} - -res += `` -fs.writeFileSync('./out/sitemap.xml', res) - - - -console.log(res) diff --git a/styl/include/_input.styl b/styl/include/_input.styl index d55b33a..240629d 100644 --- a/styl/include/_input.styl +++ b/styl/include/_input.styl @@ -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