diff --git a/next.config.js b/next.config.js index 2919f2c..253e491 100755 --- a/next.config.js +++ b/next.config.js @@ -7,22 +7,27 @@ module.exports = { config.experiments = { asset: true }; config.module.rules.push( + { + test: /\.ya?ml$/, + use: 'js-yaml-loader', + + }, { test: /\.svg$/, - use: [{ loader: "@svgr/webpack" }] + use: [{ loader: "@svgr/webpack" }], }, { test: /\.md$/, - type: 'asset/source' + type: 'asset/source', }, { test: /\.otf$/, - type: 'asset/resource' + type: 'asset/resource', }, { resourceQuery: /raw/, type: 'asset/source', - } + }, ); return config diff --git a/package-lock.json b/package-lock.json index 1232c72..0a441e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "@types/react": "^17.0.37", "dotenv": "^10.0.0", "gray-matter": "^4.0.3", + "js-yaml-loader": "^1.2.2", "next": "^11.1.4", "normalize.css": "^8.0.1", "react": "^17.0.2", @@ -3643,7 +3644,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", - "dev": true, "engines": { "node": ">= 4" } @@ -5256,6 +5256,40 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/js-yaml-loader": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/js-yaml-loader/-/js-yaml-loader-1.2.2.tgz", + "integrity": "sha512-H+NeuNrG6uOs/WMjna2SjkaCw13rMWiT/D7l9+9x5n8aq88BDsh2sRmdfxckWPIHtViYHWRG6XiCKYvS1dfyLg==", + "dependencies": { + "js-yaml": "^3.13.1", + "loader-utils": "^1.2.3", + "un-eval": "^1.2.0" + } + }, + "node_modules/js-yaml-loader/node_modules/json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "json5": "lib/cli.js" + } + }, + "node_modules/js-yaml-loader/node_modules/loader-utils": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", + "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "dependencies": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^1.0.1" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -8141,6 +8175,11 @@ "node": ">=4.2.0" } }, + "node_modules/un-eval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/un-eval/-/un-eval-1.2.0.tgz", + "integrity": "sha512-Wlj/pum6dQtGTPD/lclDtoVPkSfpjPfy1dwnnKw/sZP5DpBH9fLhBgQfsqNhe5/gS1D+vkZUuB771NRMUPA5CA==" + }, "node_modules/unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", @@ -11206,8 +11245,7 @@ "emojis-list": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", - "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", - "dev": true + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==" }, "encoding": { "version": "0.1.13", @@ -12367,6 +12405,36 @@ "esprima": "^4.0.0" } }, + "js-yaml-loader": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/js-yaml-loader/-/js-yaml-loader-1.2.2.tgz", + "integrity": "sha512-H+NeuNrG6uOs/WMjna2SjkaCw13rMWiT/D7l9+9x5n8aq88BDsh2sRmdfxckWPIHtViYHWRG6XiCKYvS1dfyLg==", + "requires": { + "js-yaml": "^3.13.1", + "loader-utils": "^1.2.3", + "un-eval": "^1.2.0" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "requires": { + "minimist": "^1.2.0" + } + }, + "loader-utils": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", + "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^1.0.1" + } + } + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -14472,6 +14540,11 @@ "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", "dev": true }, + "un-eval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/un-eval/-/un-eval-1.2.0.tgz", + "integrity": "sha512-Wlj/pum6dQtGTPD/lclDtoVPkSfpjPfy1dwnnKw/sZP5DpBH9fLhBgQfsqNhe5/gS1D+vkZUuB771NRMUPA5CA==" + }, "unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", diff --git a/package.json b/package.json index 585ebb4..499de45 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@types/react": "^17.0.37", "dotenv": "^10.0.0", "gray-matter": "^4.0.3", + "js-yaml-loader": "^1.2.2", "next": "^11.1.4", "normalize.css": "^8.0.1", "react": "^17.0.2", diff --git a/pages/playlists.tsx b/pages/playlists.tsx index b13ed99..8d1141c 100644 --- a/pages/playlists.tsx +++ b/pages/playlists.tsx @@ -1,5 +1,6 @@ import React, { ReactElement } from 'react'; import Layout from '../components/layout'; +import pl from '../public/playlists.yaml'; type listItem = { children?: listItem[]; @@ -7,27 +8,7 @@ type listItem = { title: string; }; -const list: listItem[] = [{ - title: 'Classical by Composer', - children: [ - { - title: '[Youtube] Antonio Lucio Vivaldi', - url: 'https://youtube.com/playlist?list=PLSU6wJEYct5HslkoJWHQFCttB-lhSwVr2' - }, - { - title: '[Youtube] Johann Sebastian Bach', - url: 'https://youtube.com/playlist?list=PLSU6wJEYct5HftuY6UunC6zE_QMXOGmhm' - }, - { - title: '[Youtube] Ludwig van Beethoven', - url: 'https://youtube.com/playlist?list=PLSU6wJEYct5Etx0WAXUQ7YXe84Fp5E142' - }, - { - title: '[Youtube] Wolfgang Amadeus Mozart', - url: 'https://youtube.com/playlist?list=PLSU6wJEYct5EJsE-9Zh-jWckBuZAmIt8Q' - } - ] -}]; +const list: listItem[] = pl; function mapChild(obj: listItem, level: number) { if (obj.url) diff --git a/pages/posts/[page].tsx b/pages/posts/[page].tsx index 2d7f9d7..aff903a 100644 --- a/pages/posts/[page].tsx +++ b/pages/posts/[page].tsx @@ -1,6 +1,6 @@ import Layout from '../../components/layout'; import { useRouter } from 'next/router'; -import { getAllPosts, getPost } from '../../lib/slug'; +import { getAllPosts, getPost } from '../../util/slug'; import ReactMarkdown from 'react-markdown'; import Image from 'next/image'; diff --git a/pages/posts/index.tsx b/pages/posts/index.tsx index 6b92374..0508324 100644 --- a/pages/posts/index.tsx +++ b/pages/posts/index.tsx @@ -1,7 +1,6 @@ import Link from 'next/link'; import React from 'react'; import Layout from '../../components/layout'; -import { getAllPosts } from '../../lib/slug'; import Pages from '../../public/pages.json'; import cachePostLinkData from '../../util/post-cache'; diff --git a/pages/recommended.tsx b/pages/recommended.tsx index 2038353..6b624f2 100644 --- a/pages/recommended.tsx +++ b/pages/recommended.tsx @@ -1,6 +1,7 @@ import React, { ReactElement } from 'react'; import Layout from '../components/layout'; import style from '../styles/lists.module.css'; +import rec from '../public/recommended.yaml'; type listItem = { children?: listItem[] | string[]; @@ -9,151 +10,11 @@ type listItem = { description?: string }; -const list: listItem[] = [ - { - title: 'Books', - children: [ - { - title: 'Technology', - children: [ - { - title: 'C programming', - children: [ - { - title: 'The C Programming Language [K&R]', - url: 'https://en.wikipedia.org/wiki/The_C_Programming_Language' - }, - { - title: 'Expert C Programming by Peter van der Linden' - }, - { - title: 'Practical C Programming by Steve Oualline (outdated like all the books in this section but still good)' - }, - { - title: 'Mastering Algorithms with C by Kyle Loudon' - } - ] - }, - { - title: 'Other Programming', - children: [ - 'Programming Perl by Larry Wall [Camel Book] (one of the first programming books I used. It probably is outdated but it is written well)', - 'Programming Rust: Fast, Safe Systems Development', - 'The Rust Programming Language', - 'Programming in Lua, Fourth Edition by Roberto Ierusalimschy' - ] - }, - { - title: 'Operating Systems', - children: [ - 'Advanced Programming in the Unix Environment by W. Richard Stevens', - 'Operating Systems: Design and Implementation by Andrew S. Tanenbaum (I have not had a chance to read his other books on OS. I am not a fan of his networking book though.)' - ] - }, - // { - // title: 'Networking' - // }, - // { - // title: 'Electronics' - // }, - { - title: 'Computer Engineering', - children: [ - 'Making Embedded Systems: Design Patterns for Great Software by Elecia White', - 'Computer Organization and Design: the Hardware/Software Interface [Patterson Hennessy]', - 'Computer Architecture: A Quantitative Approach [Hennessy Patterson]' - ] - }, - { - title: 'Compilers', - children: [ - { - title: 'Compilers: Principles, Techniques, and Tools [Dragon Book] (discusses theory in detail so it is kind of hard to read)' - } - ] - }, - { - title: 'Other', - children: [ - { - title: 'Definitive Guide to sed: Tutorial and Reference' - } - ] - } - ] - }, - { - title: 'Classics', - description: 'Only the English ones for now.', - children: [ - 'Christmas Carol', - 'A Tale of Two Cities', - 'The Mayor of Casterbridge', - 'The Citadel', - 'Oliver Twist', - 'Macbeth', - 'Othello', - 'Adventures of Huckleberry Finn', - 'Murder on the Orient Express' - ] - }, - { - title: 'Language Learning', - children: ['Lingua Latina per se Illustrata (Both parts)'] - } - ] - }, - { - title: 'Movies', - children: [ - 'Pulp Fiction', - 'Blade Runner 2049', - 'The Grand Budapest Hotel', - 'The Hateful Eight', - 'Goodfellas', - 'Inception', - 'Memento', - 'Dune (2021)', - 'Hot Fuzz', - 'Snatch' - ] - }, - { - title: 'Music', - children: [ - 'American Pie by Don McLean', - 'L\'Ultima Diligenza by Ennio Morricone' - ] - }, - { - title: 'Classical Music', - children: [ - 'Große Fuge Op. 133', - 'KV 387', - 'KV 448', - 'KV 626', - 'Piano Sonata No. 2 Mvmt. 3 (Chopin)', - 'BWV 1048', - 'Prelude in G Minor (Op. 23 No. 5)', - 'String Quartet, Op. 20 No. 2 (Haydn)', - 'Arabesque No. 1 (Debussy)' - ] - }, - { - title: 'Video Games', - children: [ - 'The Legend of Zelda: Breath of the Wild', - 'Portal 2', - 'Factorio', - 'The Witcher 3: The Wild Hunt GOTY Edition (Especially the DLCs)', - 'Baba is You', - 'Red Dead Redemption' - ] - } -]; +const list: listItem[] = rec // todo: validate this function mapChild(obj: listItem | string, level: number) { - if (typeof obj === 'string') { +console.log(list) +if (typeof obj === 'string') { if (obj === '') return <> return {obj} diff --git a/pages/resources.tsx b/pages/resources.tsx index 7ffc43b..ee01824 100644 --- a/pages/resources.tsx +++ b/pages/resources.tsx @@ -1,6 +1,7 @@ import React, { ReactElement } from 'react'; import Layout from '../components/layout'; import style from '../styles/lists.module.css'; +import res from '../public/resources.yaml'; type listItem = { children?: listItem[] | string[]; @@ -9,80 +10,7 @@ type listItem = { description?: string }; -const list = [{ - title: 'Programming', - children: [ - { - url: 'http://aggregate.org/MAGIC/', - title: 'The Aggregate Magic Algorithms' - }, - { - url: 'https://3fx.ch/typing-is-hard.html', - title: 'Typing is Hard' - }, - { - url: 'https://www.atlassian.com/git/', - title: 'Atlassian\'s Git Guide' - }, - { - url: 'https://learnopengl.com/', - title: 'LearnOpenGL.com' - }, - { - url: 'http://ctan.math.utah.edu/ctan/tex-archive/info/symbols/comprehensive/symbols-letter.pdf', - title: '[PDF] LaTeX Symbols' - }, - { - url: 'https://tobi.oetiker.ch/lshort/lshort.pdf', - title: '[PDF] The Not So Short Introduction to LATEX 2ε' - - }, - { - url: 'https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html', - title: 'The MIT License, Line by Line by Kyle E. Mitchell' - }, - { - title: 'Posts', - children: [ - { - title: 'How to Make Your Code Reviewer Fall in Love with You by Michael Lynch', - url: 'https://mtlynch.io/code-review-love/' - }, - { - title: 'What\'s in the box? by @fasterthanlime', - url: 'https://fasterthanli.me/articles/whats-in-the-box' - } - ] - }, - { - title: 'Talks', - children: [ - { - title: 'Concurrency is not Parallelism by Rob Pike', - url: 'https://talks.golang.org/2012/waza.slide' - } - ] - } - ] -}, -{ - title: 'Electrical', - children: [ - { - title: 'Common Wire-To-Board, Wire-To-Wire Connectors, And Crimp Tools', - url: 'http://www.mattmillman.com/info/crimpconnectors/' - } - ] -}, -{ - title: 'Other Topics', - children: [ - { - title: 'Sight Reading Trainer', - url: 'https://sightreading.training/' - } - ] -}]; +const list: listItem[] = res; function mapChild(obj: listItem | string, level: number) { if (typeof obj === 'string') { diff --git a/public/playlists.yaml b/public/playlists.yaml new file mode 100644 index 0000000..b6898b7 --- /dev/null +++ b/public/playlists.yaml @@ -0,0 +1,11 @@ +- title: Classical by Composer + children: + - title: "[Youtube] Antonio Lucio Vivaldi" + url: https://youtube.com/playlist?list=PLSU6wJEYct5HslkoJWHQFCttB-lhSwVr2 + - title: "[Youtube] Johann Sebastian Bach" + url: https://youtube.com/playlist?list=PLSU6wJEYct5HftuY6UunC6zE_QMXOGmhm + - title: "[Youtube] Ludwig van Beethoven" + url: https://youtube.com/playlist?list=PLSU6wJEYct5Etx0WAXUQ7YXe84Fp5E142 + - title: "[Youtube] Wolfgang Amadeus Mozart" + url: https://youtube.com/playlist?list=PLSU6wJEYct5EJsE-9Zh-jWckBuZAmIt8Q + \ No newline at end of file diff --git a/public/recommended.yaml b/public/recommended.yaml new file mode 100644 index 0000000..465de1f --- /dev/null +++ b/public/recommended.yaml @@ -0,0 +1,89 @@ +- title: Books + hey: sdf + children: + - title: Technology + children: + - title: C programming + children: + - title: The C Programming Language [K&R] + url: https://en.wikipedia.org/wiki/The_C_Programming_Language + - title: Expert C Programming by Peter van der Linden + - title: Practical C Programming by Steve Oualline (outdated like all the books + in this section but still good) + - title: Mastering Algorithms with C by Kyle Loudon + - title: Other Programming + children: + - Programming Perl by Larry Wall [Camel Book] (one of the first programming + books I used. It probably is outdated but it is written well) + - 'Programming Rust: Fast, Safe Systems Development' + - The Rust Programming Language + - Programming in Lua, Fourth Edition by Roberto Ierusalimschy + - title: Operating Systems + children: + - Advanced Programming in the Unix Environment by W. Richard Stevens + - 'Operating Systems: Design and Implementation by Andrew S. Tanenbaum (I have + not had a chance to read his other books on OS. I am not a fan of his networking + book though.)' + - title: Computer Engineering + children: + - 'Making Embedded Systems: Design Patterns for Great Software by Elecia White' + - 'Computer Organization and Design: the Hardware/Software Interface [Patterson + Hennessy]' + - 'Computer Architecture: A Quantitative Approach [Hennessy Patterson]' + - title: Compilers + children: + - title: 'Compilers: Principles, Techniques, and Tools [Dragon Book] (discusses + theory in detail so it is kind of hard to read)' + - title: Other + children: + - title: 'Definitive Guide to sed: Tutorial and Reference' + - title: Classics + description: Only the English ones for now. + children: + - Christmas Carol + - A Tale of Two Cities + - The Mayor of Casterbridge + - The Citadel + - Oliver Twist + - Macbeth + - Othello + - Adventures of Huckleberry Finn + - Murder on the Orient Express + - title: Language Learning + children: + - Lingua Latina per se Illustrata (Both parts) +- title: Movies + children: + - Pulp Fiction + - Blade Runner 2049 + - The Grand Budapest Hotel + - The Hateful Eight + - Goodfellas + - Inception + - Memento + - Dune (2021) + - Hot Fuzz + - Snatch +- title: Music + children: + - American Pie by Don McLean + - L'Ultima Diligenza by Ennio Morricone +- title: Classical Music + children: + - Große Fuge Op. 133 + - KV 387 + - KV 448 + - KV 626 + - Piano Sonata No. 2 Mvmt. 3 (Chopin) + - BWV 1048 + - Prelude in G Minor (Op. 23 No. 5) + - String Quartet, Op. 20 No. 2 (Haydn) + - Arabesque No. 1 (Debussy) +- title: Video Games + children: + - 'The Legend of Zelda: Breath of the Wild' + - Portal 2 + - Factorio + - 'The Witcher 3: The Wild Hunt GOTY Edition (Especially the DLCs)' + - Baba is You + - Red Dead Redemption diff --git a/public/resources.yaml b/public/resources.yaml new file mode 100644 index 0000000..02bba4f --- /dev/null +++ b/public/resources.yaml @@ -0,0 +1,34 @@ +- title: Programming + children: + - url: http://aggregate.org/MAGIC/ + title: The Aggregate Magic Algorithms + - url: https://3fx.ch/typing-is-hard.html + title: Typing is Hard + - url: https://www.atlassian.com/git/ + title: Atlassian's Git Guide + - url: https://learnopengl.com/ + title: LearnOpenGL.com + - url: http://ctan.math.utah.edu/ctan/tex-archive/info/symbols/comprehensive/symbols-letter.pdf + title: "[PDF] LaTeX Symbols" + - url: https://tobi.oetiker.ch/lshort/lshort.pdf + title: "[PDF] The Not So Short Introduction to LATEX 2ε" + - url: https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html + title: The MIT License, Line by Line by Kyle E. Mitchell + - title: Posts + children: + - title: How to Make Your Code Reviewer Fall in Love with You by Michael Lynch + url: https://mtlynch.io/code-review-love/ + - title: What's in the box? by @fasterthanlime + url: https://fasterthanli.me/articles/whats-in-the-box + - title: Talks + children: + - title: Concurrency is not Parallelism by Rob Pike + url: https://talks.golang.org/2012/waza.slide +- title: Electrical + children: + - title: Common Wire-To-Board, Wire-To-Wire Connectors, And Crimp Tools + url: http://www.mattmillman.com/info/crimpconnectors/ +- title: Other Topics + children: + - title: Sight Reading Trainer + url: https://sightreading.training/ diff --git a/util/post-cache.ts b/util/post-cache.ts index 08938db..dd5399b 100644 --- a/util/post-cache.ts +++ b/util/post-cache.ts @@ -1,5 +1,5 @@ import fs from 'fs'; -import { getAllPosts } from '../lib/slug'; +import { getAllPosts } from './slug'; import { join } from 'path'; const publicDir = join(process.cwd(), 'public'); diff --git a/lib/slug.ts b/util/slug.ts similarity index 89% rename from lib/slug.ts rename to util/slug.ts index 4e262fd..6785aa6 100644 --- a/lib/slug.ts +++ b/util/slug.ts @@ -39,5 +39,9 @@ export function getPost(rawslug: string, filter: Array = []) { export function getAllPosts(filter: Array = []) { const files = fs.readdirSync(postsDirectory); - return files.map(file => { return getPost(file, filter) }); + return files + .filter(c => !c.match(/^\./)) + .map(file => { + return getPost(file, filter) + }); } \ No newline at end of file