-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Shipping log section with the last 3 posts from the blog #97
Open
Pabl0cks
wants to merge
9
commits into
master
Choose a base branch
from
blog
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7e3836a
Add blog section initial commit
Pabl0cks ee5861a
Remove fetch logic from component to send posts with prop
Pabl0cks 0d0336d
Remove cors
Pabl0cks 0b56183
Tweak color handling and move BlogSection component to the right folder
Pabl0cks c25e715
Move date formatting logic out from frontend component
Pabl0cks 15604f0
Manage error on fetching posts
Pabl0cks 5049440
Merge branch 'master' into blog
Pabl0cks 4755bdd
Rename fetch to get for consistency
Pabl0cks 69525d8
Fix merge problems
Pabl0cks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const express = require("express"); | ||
const axios = require("axios"); | ||
const xml2js = require("xml2js"); | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/posts", async (req, res) => { | ||
try { | ||
const response = await axios.get("https://buidlguidl.substack.com/feed"); | ||
const xml = response.data; | ||
const parser = new xml2js.Parser(); | ||
|
||
parser.parseString(xml, (err, result) => { | ||
if (err) { | ||
console.error("Failed to parse blog feed:", err); | ||
res.status(500).json({ error: "Failed to parse blog feed" }); | ||
} else { | ||
const posts = result.rss.channel[0].item.map(item => { | ||
const date = new Date(item.pubDate[0]); | ||
const formattedDate = `${date.toLocaleString('default', { month: 'short' }).toUpperCase()} ${date.getDate()}`; | ||
|
||
return { | ||
title: item.title[0], | ||
description: item.description[0], | ||
link: item.link[0], | ||
pubDate: formattedDate, | ||
imageUrl: item.enclosure ? item.enclosure[0].$.url : null | ||
}; | ||
}); | ||
|
||
res.status(200).json(posts.slice(0, 3)); // Return the last 3 posts | ||
} | ||
}); | ||
} catch (error) { | ||
console.error("Error fetching blog posts:", error); | ||
res.status(500).json({ error: "Internal Server Error" }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { Container, VStack, Box, Heading, Text, Image, Link, Flex } from '@chakra-ui/react'; | ||
import useCustomColorModes from "../../hooks/useCustomColorModes"; | ||
|
||
const BlogSection = ({ posts }) => { | ||
const { baseColor, secondaryFontColor } = useCustomColorModes(); | ||
|
||
if (!posts || posts.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Container maxW="container.lg" mb="50px"> | ||
<Heading fontWeight="500" mb={8} mt={20}> | ||
Shipping Log | ||
</Heading> | ||
|
||
{posts.map((post, index) => ( | ||
<Link key={index} href={post.link} isExternal> | ||
<Box bg="transparent" w="full" mb={4}> | ||
<Box bg={baseColor} rounded="md" shadow="md" w="full"> | ||
<Flex alignItems="stretch" justifyContent="space-between" w="full"> | ||
<VStack align="start" spacing={4} flex="1" p={6}> | ||
<Heading as="h3" size="md">{post.title}</Heading> | ||
<Text fontSize="sm" noOfLines={3}>{post.description}</Text> | ||
<Text color={secondaryFontColor} fontSize="sm">{post.pubDate}</Text> | ||
</VStack> | ||
<Image display={{ base: "none", md: "block" }} maxW="200px" src={post.imageUrl} alt={post.title} objectFit="cover" /> | ||
</Flex> | ||
</Box> | ||
</Box> | ||
</Link> | ||
))} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default BlogSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import axios from "axios"; | ||
import { SERVER_URL as serverUrl } from "../../constants"; | ||
|
||
export const fetchRecentPosts = async () => { | ||
try { | ||
const response = await axios.get(`${serverUrl}/blog/posts`); | ||
return response.data; | ||
} catch (error) { | ||
console.error("Error fetching recent posts:", error); | ||
return []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe
get
is more consistent thanfetch
:D