From b39d26f3c486f30d3f744d6b3c4fb2323e4159e1 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+stjet@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:39:00 +0530 Subject: [PATCH] archived posts, new ryuji feature --- index.ts | 43 ++++++++++++++---------- package.json | 8 ++--- posts/_metadata.json | 15 +++++++-- posts/archived_post.md | 1 + ryuji.ts | 19 ++++++++--- templates/archive.html | 39 +++++++++++++++++++++ templates/components/random/archive.html | 6 ++++ templates/components/random/badges.html | 2 +- templates/index.html | 4 ++- 9 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 posts/archived_post.md create mode 100644 templates/archive.html create mode 100644 templates/components/random/archive.html diff --git a/index.ts b/index.ts index d76b226..ec37e92 100644 --- a/index.ts +++ b/index.ts @@ -7,30 +7,31 @@ import _posts_metadata from "./posts/_metadata.json"; import _site_info from "./site_info.json"; export interface PostMetadata { - title: string, - slug: string, - filename: string, - date: string, - author: string, - tags: string[], + title: string; + slug: string; + filename: string; + date: string; + author: string; + tags: string[]; + archived: boolean; } export interface Post extends PostMetadata { - md_lines: string[], - html: string, - tags_exist: boolean, + md_lines: string[]; + html: string; + tags_exist: boolean; } export interface RSSPost extends PostMetadata { - url: string, - last_updated: string, - html: string, + url: string; + last_updated: string; + html: string; } export interface SiteInfo { - title: string, - url: string, - icon: string, + title: string; + url: string; + icon: string; } let renderer: Renderer = new Renderer("templates", "components"); @@ -42,7 +43,13 @@ builder.serve_static_folder("static"); //home page builder.serve_template(renderer, "/", "index", { - posts: posts_metadata, + posts: posts_metadata.filter((post) => !post.archived), +}); + +//archive page +builder.serve_template(renderer, "/archive", "archive", { + archived_posts: posts_metadata.filter((post) => post.archived), + no_archived_posts: posts_metadata.filter((post) => post.archived).length === 0, }); //404 page (github pages) @@ -86,7 +93,7 @@ for (let i=0; i < posts_metadata.length; i++) { { post, next_post, - author_expected: post.author.toLowerCase().startsWith("jetstream0") || post.author.toLowerCase().startsWith("prussia"), + author_expected: post.author.toLowerCase().startsWith("jetstream0") || post.author.toLowerCase().startsWith("prussia") || post.author.toLowerCase().startsWith("stjet"), } ); } @@ -110,7 +117,7 @@ for (let i=0; i < tags.length; i++) { builder.serve_templates(renderer, tags_serve_paths, "tags", tags_vars); //build rss feed -let first_posts: PostMetadata[] = posts_metadata.slice(0, 5); //not truly the recents, actually the first 5 posts in the json file, which is decided by me and usually the most recent posts +let first_posts: PostMetadata[] = posts_metadata.filter((post) => !post.archived).slice(0, 5); //not truly the recents, actually the first 5 posts in the json file, which is decided by me and usually the most recent posts const site_info: SiteInfo = _site_info; diff --git a/package.json b/package.json index 306857c..b868b4a 100644 --- a/package.json +++ b/package.json @@ -10,14 +10,14 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/jetstream0/hedgeblog.git" + "url": "git+https://github.com/stjet/hedgeblog.git" }, - "author": "jetstream0/prussia", + "author": "stjet/prussia", "license": "AGPL-3.0", "bugs": { - "url": "https://github.com/jetstream0/hedgeblog/issues" + "url": "https://github.com/stjet/hedgeblog/issues" }, - "homepage": "https://github.com/jetstream0/hedgeblog#readme", + "homepage": "https://github.com/stjet/hedgeblog#readme", "dependencies": { "makoto": "^1.0.1" }, diff --git a/posts/_metadata.json b/posts/_metadata.json index 744be47..52ef3aa 100644 --- a/posts/_metadata.json +++ b/posts/_metadata.json @@ -5,7 +5,8 @@ "filename": "example", "date": "30/12/1999", "author": "Prussia", - "tags": ["example", "fake", "please remember to remove"] + "tags": ["example", "fake", "please remember to remove"], + "archived": false }, "another_example": { "title": "Another Example!", @@ -13,6 +14,16 @@ "filename": "another_example", "date": "31/07/2023", "author": "John Dough", - "tags": ["example", "jia", "please remember to remove"] + "tags": ["example", "jia", "please remember to remove"], + "archived": false + }, + "archived_post": { + "title": "Archived Post", + "slug": "archived", + "filename": "archived_post", + "date": "17/01/2024", + "author": "John Dough", + "tags": ["example"], + "archived": true } } \ No newline at end of file diff --git a/posts/archived_post.md b/posts/archived_post.md new file mode 100644 index 0000000..c5d436a --- /dev/null +++ b/posts/archived_post.md @@ -0,0 +1 @@ +This post is *archived*. diff --git a/ryuji.ts b/ryuji.ts index 221e8ca..6ecd3d5 100644 --- a/ryuji.ts +++ b/ryuji.ts @@ -1,6 +1,6 @@ import { readFileSync } from "fs"; -export const SYNTAX_REGEX = /\[\[ [a-zA-Z0-9.:/\-_!]+ \]\]/g; +export const SYNTAX_REGEX = /\[\[ [a-zA-Z0-9.:/\*\-_!]+ \]\]/g; export type file_extension = `.${string}`; @@ -89,10 +89,10 @@ export class Renderer { if (recursion_layer > 5) throw Error("Components more than 5 layers deep, components may be referencing each other in infinite loop."); if (typeof exp_parts[1] !== "string") throw Error("`component:` statement missing component file name afterwards"); let file_name: string = exp_parts[1]; - if (!file_name.includes(".")) { - file_name += this.file_extension; - } - rendered += this.render_template(Renderer.concat_path(this.components_dir, file_name), vars, recursion_layer+1); + if (!file_name.includes(".")) { + file_name += this.file_extension; + } + rendered += this.render_template(Renderer.concat_path(this.components_dir, file_name), vars, recursion_layer+1); } else if (exp_parts[0] === "for") { if (for_loops[for_loops.length-1]?.index === index) { //for loop already exists, just continue and do nothing @@ -185,12 +185,21 @@ export class Renderer { } else { //compare with second var let var_name2: string = exp_parts[2]; + let if_in: boolean = false; let if_not: boolean = false; + //*! is valid + if (var_name2.startsWith("*")) { + var_name2 = var_name2.slice(1, var_name2.length); + if_in = true; + } if (var_name2.startsWith("!")) { var_name2 = var_name2.slice(1, var_name2.length); if_not = true; } let var_value2 = Renderer.get_var(var_name2, vars); + if (if_in) { + var_value2 = var_value2.find((ele) => ele === var_value); + } if (if_not) { //make sure the two compared variables are NOT equal if (var_value !== var_value2) { diff --git a/templates/archive.html b/templates/archive.html new file mode 100644 index 0000000..00be603 --- /dev/null +++ b/templates/archive.html @@ -0,0 +1,39 @@ + + + + + + prussia fan club + + + + + + + [[ component:return ]] + [[ component:dark-mode-checkbox ]] +
+
+ +
+

prussiafan.club

+
+

This is the archive of my blog, where posts bad enough to be hidden, but not terrible enough to be deleted, live.

+

Ah, what else? Uhhh... My favourite projects at the moment are pla-den-tor, ztmy, bananopie, mingde, and this blog. My favourite language is probably Lisp Scheme, but Typescript is nice too, except when it isn't.

+

You can also hire me!

+
+
+ +
+
+ + + +//, and a place where you can hire me \ No newline at end of file diff --git a/templates/components/random/archive.html b/templates/components/random/archive.html new file mode 100644 index 0000000..806ae57 --- /dev/null +++ b/templates/components/random/archive.html @@ -0,0 +1,6 @@ +
+
+ Visit the archives +
+ More random stuff +
diff --git a/templates/components/random/badges.html b/templates/components/random/badges.html index 8346056..3f2f87c 100644 --- a/templates/components/random/badges.html +++ b/templates/components/random/badges.html @@ -8,5 +8,5 @@ Certified mostly harmless Salt your passwords, OR ELSE! - More random stuff + More random stuff diff --git a/templates/index.html b/templates/index.html index 11b5c2a..53ca30a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@ + [[ component:dark-mode-checkbox ]] @@ -16,7 +17,7 @@

prussiafan.club


-

This is my blog. I also have a portfolio, retro style personal website, and a place where you can hire me.

+

This is my blog. I also have a portfolio, retro style personal website. I like free software, privacy, yada yada.

[[ component:random/badges ]] + [[ component:random/archive ]] [[ component:random/quote1 ]] [[ component:random/quote2 ]] [[ component:random/minesweeper ]]