From 57016f4f3f7662fc67b524073423128db5de064d Mon Sep 17 00:00:00 2001 From: "hexlocation's laptop (asiago)" Date: Fri, 29 Mar 2024 09:15:24 -0400 Subject: [PATCH] doing stuff l8r --- Dockerfile | 4 +-- config.json => data/config.json | 0 .../default_posts}/about.md | 0 .../default_posts}/contact.md | 0 .../default_posts}/hello.md | 0 {default_posts => data/default_posts}/lol.md | 0 .../default_templates}/footer.ejs | 0 .../default_templates}/global-style.ejs | 0 .../default_templates}/header.ejs | 0 .../default_templates}/index.ejs | 0 .../default_templates}/post.ejs | 0 index.ts | 6 ++--- scripts/docker_run.sh | 25 +++++++++++++++++-- 13 files changed, 28 insertions(+), 7 deletions(-) rename config.json => data/config.json (100%) rename {default_posts => data/default_posts}/about.md (100%) rename {default_posts => data/default_posts}/contact.md (100%) rename {default_posts => data/default_posts}/hello.md (100%) rename {default_posts => data/default_posts}/lol.md (100%) rename {default_templates => data/default_templates}/footer.ejs (100%) rename {default_templates => data/default_templates}/global-style.ejs (100%) rename {default_templates => data/default_templates}/header.ejs (100%) rename {default_templates => data/default_templates}/index.ejs (100%) rename {default_templates => data/default_templates}/post.ejs (100%) diff --git a/Dockerfile b/Dockerfile index 21cfffe..ec1ee43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,9 @@ RUN yarn global add typescript RUN tsc RUN mkdir /app RUN cp -r /tmp/build/* /app -RUN cp -r /tmp/default_posts /app/default_posts +RUN cp -r /tmp/data/default_posts /app/default_posts RUN cp -r /tmp/node_modules /app -RUN cp -r /tmp/default_templates /app/default_templates +RUN cp -r /tmp/data/default_templates /app/default_templates COPY ./scripts/docker_run.sh /app/run.sh WORKDIR /app CMD ["/app/run.sh"] diff --git a/config.json b/data/config.json similarity index 100% rename from config.json rename to data/config.json diff --git a/default_posts/about.md b/data/default_posts/about.md similarity index 100% rename from default_posts/about.md rename to data/default_posts/about.md diff --git a/default_posts/contact.md b/data/default_posts/contact.md similarity index 100% rename from default_posts/contact.md rename to data/default_posts/contact.md diff --git a/default_posts/hello.md b/data/default_posts/hello.md similarity index 100% rename from default_posts/hello.md rename to data/default_posts/hello.md diff --git a/default_posts/lol.md b/data/default_posts/lol.md similarity index 100% rename from default_posts/lol.md rename to data/default_posts/lol.md diff --git a/default_templates/footer.ejs b/data/default_templates/footer.ejs similarity index 100% rename from default_templates/footer.ejs rename to data/default_templates/footer.ejs diff --git a/default_templates/global-style.ejs b/data/default_templates/global-style.ejs similarity index 100% rename from default_templates/global-style.ejs rename to data/default_templates/global-style.ejs diff --git a/default_templates/header.ejs b/data/default_templates/header.ejs similarity index 100% rename from default_templates/header.ejs rename to data/default_templates/header.ejs diff --git a/default_templates/index.ejs b/data/default_templates/index.ejs similarity index 100% rename from default_templates/index.ejs rename to data/default_templates/index.ejs diff --git a/default_templates/post.ejs b/data/default_templates/post.ejs similarity index 100% rename from default_templates/post.ejs rename to data/default_templates/post.ejs diff --git a/index.ts b/index.ts index 6270f84..310715f 100644 --- a/index.ts +++ b/index.ts @@ -4,13 +4,13 @@ import ejs from "ejs"; import fs from "fs"; import path from "path"; import jsdom from "jsdom"; -import config from "./config.json" +import config from "./data/config.json" let app = express(); // set view engine to ejs app.set("view engine", "ejs") -app.set('views', path.join(__dirname, 'templates')) +app.set('views', path.join(__dirname, 'data','templates')) // type for post object type Post = { @@ -29,7 +29,7 @@ async function htmlstripper(html: string){ // returns Post array async function contentScan(){ let posts: Post[] = [] - let postsDir = path.join(__dirname, "posts") + let postsDir = path.join(__dirname, 'data',"posts") let files = await fs.readdirSync(postsDir).filter((name: string) => name.toLowerCase().endsWith(".md")) for (const file of files) { let postPath = path.join(postsDir, file) diff --git a/scripts/docker_run.sh b/scripts/docker_run.sh index 6dd98fd..96d44e6 100755 --- a/scripts/docker_run.sh +++ b/scripts/docker_run.sh @@ -1,15 +1,36 @@ # I'm so bad at bash scripting +cat << EOF + + ____ ______________ __ + / __ \/ _/ ___/ ___// / + / / / // / \__ \\__ \/ / + / /_/ // / ___/ /__/ /_/ +/_____/___//____/____(_) + +EOF +if [ ! -d data ]; then + echo '-------------' + echo 'Data folder not found. Did you set up a volume?' + echo '-------------' + exit 1 +fi +if [ ! -f data/config.json ]; then + echo '-------------' + echo 'Config file not found. Please create one.' + echo '-------------' + exit 1 +fi if [ -z "$(find posts -mindepth 1 -maxdepth 1)" ]; then echo '-------------' echo 'Posts directory is empty, copying default...' echo '-------------' - cp -r default_posts/* posts + cp -r default_posts/* data/posts fi if [ -z "$(find templates -mindepth 1 -maxdepth 1)" ]; then echo '-------------' echo 'Template directory is empty, copying default...' echo '-------------' - cp -r default_templates/* templates + cp -r default_templates/* data/templates fi