From f86697e00dadd6ed16bc0ec17b3cfa8668162eb5 Mon Sep 17 00:00:00 2001 From: log101 Date: Wed, 12 Jun 2024 15:10:14 +0300 Subject: [PATCH] refactor: simplify code --- Dockerfile | 28 -------- src/components/EmojiReactionForm.astro | 49 +++++++++++++ src/components/Header.astro | 18 +++-- src/components/Post.astro | 68 ++++++++++--------- src/images/calendar.svg | 10 +++ src/images/questionMark.svg | 9 +++ .../category/[category]/[slug]/index.astro | 30 +------- src/scripts/utils.js | 22 ++++-- src/styles/main.css | 9 --- 9 files changed, 139 insertions(+), 104 deletions(-) delete mode 100644 Dockerfile create mode 100644 src/components/EmojiReactionForm.astro create mode 100644 src/images/calendar.svg create mode 100644 src/images/questionMark.svg diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4a295bd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -# Stage 1: Build the Astro project -FROM node:20-alpine AS builder - -WORKDIR /app - -# Copy package.json and package-lock.json files -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Copy the rest of the application files -COPY . . - -# Build the Astro project -RUN npm run build - -# Stage 2: Serve with nginx -FROM nginx:alpine - -# Copy the built static files from the builder stage -COPY --from=builder /app/dist /usr/share/nginx/html - -# Copy custom nginx configuration file if needed -# COPY default.conf /etc/nginx/conf.d/default.conf - -# Expose port 80 to the outside world -EXPOSE 80 diff --git a/src/components/EmojiReactionForm.astro b/src/components/EmojiReactionForm.astro new file mode 100644 index 0000000..31f0e37 --- /dev/null +++ b/src/components/EmojiReactionForm.astro @@ -0,0 +1,49 @@ +--- +const { entryId } = Astro.props; +const backendHost = import.meta.env.PUBLIC_BACKEND_HOST; +--- + + + +
+ +
+
+ + + + + + +
+
+
diff --git a/src/components/Header.astro b/src/components/Header.astro index ae8cd27..ccd231d 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -55,14 +55,24 @@ diff --git a/src/components/Post.astro b/src/components/Post.astro index 03c74ae..9d305a8 100644 --- a/src/components/Post.astro +++ b/src/components/Post.astro @@ -8,34 +8,53 @@ interface Props { const { post, componentType } = Astro.props; -let showTags, shortSummary, longSummary, fullText, postFooter; +// default options for the post component +const deafultOptions = { + showTags: false, + shortSummary: false, + longSummary: false, + fullText: false, + postFooter: false, +}; +const options = { ...deafultOptions }; +// Determine which options should be applied to post switch (componentType) { case "full": - postFooter = true; - showTags = true; - fullText = true; + options.postFooter = true; + options.showTags = true; + options.fullText = true; break; case "long": - longSummary = true; - showTags = true; + options.longSummary = true; + options.showTags = true; break; case "short": - shortSummary = true; + options.shortSummary = true; break; default: break; } +// Options should not mutated further +Object.freeze(options); + +// Format datae const postDateFormatted = post.data.date.toLocaleDateString("tr-TR", { day: "numeric", month: "long", year: "numeric", }); +// Create post link const postLink = `/category/${post.data.category}/${post.slug}`; +// Create post content as an astro component const { Content } = await post.render(); + +import { Image } from "astro:assets"; +import questionMark from "@/images/questionMark.svg"; +import calendar from "@/images/calendar.svg"; --- -
- -
- -
-
-
+