Skip to content

Commit

Permalink
style: change to double-quatation mark
Browse files Browse the repository at this point in the history
  • Loading branch information
JefferMarcelino committed Apr 9, 2024
1 parent 49217fa commit f56b7b3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const createPost = async (
},
});

console.log('New post created: ', newPost);
console.log("New post created: ", newPost);
} catch (error) {
console.error('Error creating post:', error);
console.error("Error creating post:", error);
} finally {
await prisma.$disconnect();
};
Expand Down Expand Up @@ -58,14 +58,14 @@ export const run = async () => {
const response = await result.response;
const text = response.text();

const [ title, ...contentWithTagsAndImage ] = text.split('\n');
const [ title, ...contentWithTagsAndImage ] = text.split("\n");

await createPost(
title.replace(/#/g, "").trim(),
contentWithTagsAndImage.join("\n")
);
} catch (error) {
console.error('Error creating post:', error);
console.error("Error creating post:", error);
} finally {
await prisma.$disconnect();
};
Expand Down
38 changes: 19 additions & 19 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fastify from "fastify";
import cors from "@fastify/cors";
import view from "@fastify/view";
import { PrismaClient } from '@prisma/client';
import { PrismaClient } from "@prisma/client";
import ejs from "ejs"
import path from 'path';
import path from "path";
import dayjs from "dayjs";
import showdown from "showdown";
import { run } from "./generator";
Expand All @@ -15,7 +15,7 @@ app.register(view, {
engine: {
ejs: ejs,
},
root: path.join(__dirname, 'templates')
root: path.join(__dirname, "templates")
});

const converter = new showdown.Converter({
Expand All @@ -26,29 +26,29 @@ const converter = new showdown.Converter({

const prisma = new PrismaClient();

app.get('/', async (request, reply) => {
app.get("/", async (request, reply) => {
try {
const posts = await prisma.post.findMany({
orderBy: {
createdAt: "desc"
}
});

reply.type('text/html').code(200);
return reply.view('index.ejs', { posts: posts.map(item => {
reply.type("text/html").code(200);
return reply.view("index.ejs", { posts: posts.map(item => {
return {
...item,
createdAt: dayjs(item.createdAt).format('MMMM D, YYYY HH:mm')
createdAt: dayjs(item.createdAt).format("MMMM D, YYYY HH:mm")
}
}) });
} catch (error) {
console.error('Error fetching blog posts:', error);
console.error("Error fetching blog posts:", error);
reply.status(500);
return 'Error fetching blog posts';
return "Error fetching blog posts";
}
});

app.get('/post/:postId', async (request, reply) => {
app.get("/post/:postId", async (request, reply) => {
try {
const { postId } = request.params as { postId: string }

Expand All @@ -60,33 +60,33 @@ app.get('/post/:postId', async (request, reply) => {

if (!post) {
reply.code(404);
return 'Post not found';
return "Post not found";
}

const formattedCreatedAt = dayjs(post.createdAt).format('MMMM D, YYYY HH:mm');
const formattedCreatedAt = dayjs(post.createdAt).format("MMMM D, YYYY HH:mm");

reply.type('text/html').code(200);
return reply.view('post.ejs', {
reply.type("text/html").code(200);
return reply.view("post.ejs", {
post: {
...post,
createdAt: formattedCreatedAt,
content: converter.makeHtml(post.content)
},
});
} catch (error) {
console.error('Error fetching blog post:', error);
return 'Error fetching blog post';
console.error("Error fetching blog post:", error);
return "Error fetching blog post";
}
});

app.get('/generate', async (request, reply) => {
app.get("/generate", async (request, reply) => {
try {
await run();
return { message: "Okay " };
} catch (error) {
console.error('Error fetching blog posts:', error);
console.error("Error fetching blog posts:", error);
reply.status(500);
return 'Error fetching blog posts';
return "Error fetching blog posts";
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/templates/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Blog</title>

<style>
@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');
@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");
</style>

<style>
Expand Down Expand Up @@ -153,7 +153,7 @@
<%= post.title %>
</h3>
<p class="description">
<%= post.content.substring(0, 200) + (post.content.length > 100 ? '...' : '') %>
<%= post.content.substring(0, 200) + (post.content.length > 100 ? "..." : "") %>
</p>
</a>
<% }); %>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title><%= post.title %></title>

<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap");
</style>

<style>
Expand Down

0 comments on commit f56b7b3

Please sign in to comment.