-
-
Notifications
You must be signed in to change notification settings - Fork 38
blog: add related posts for blog page #350
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc3c453
blog: update supabase rls alternative
jiashengguo bb8fc8d
blog: add related posts for blog page
jiashengguo deb9ce9
Merge remote-tracking branch 'origin/main' into jiasheng
jiashengguo 0d9415c
remove console.log
jiashengguo 99995f3
at least make 3 related posts
jiashengguo 74b82e9
update style
jiashengguo 1cd79e5
add CTA to doc
jiashengguo cb5724d
display max 3 lines for description
jiashengguo 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,76 @@ | ||
| import React from 'react'; | ||
| import Link from '@docusaurus/Link'; | ||
|
|
||
| import clsx from 'clsx'; | ||
|
|
||
| export const PostPaginator = ({ posts, title }) => { | ||
| if (posts.length < 1) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={clsx( | ||
| 'mr-auto w-full', | ||
| 'py-10', | ||
| 'blog-sm:py-12', | ||
| 'blog-md:py-16', | ||
| 'max-w-[894px]', | ||
| 'blog-sm:max-w-screen-blog-sm', | ||
| 'blog-lg:max-w-screen-content-2xl' | ||
| )} | ||
| > | ||
| <div className="blog-sm:px-6 w-full"> | ||
| <h2 className="mb-4 p-0 text-2xl font-semibold">{title}</h2> | ||
| <div className="flex flex-col not-prose "> | ||
| {posts.map((post) => ( | ||
| <Link | ||
| to={post.permalink} | ||
| rel="dofollow" | ||
| key={post.permalink ?? post.id} | ||
|
Comment on lines
+29
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the
- rel="dofollow"
+ rel="nofollow"
- to={post.permalink}Also applies to: 51-51 |
||
| style={{ color: 'var(--ifm-font-color-base)' }} | ||
| className={clsx( | ||
| 'flex', | ||
| 'flex-col', | ||
| 'gap-2', | ||
| 'p-5', | ||
| 'mb-5', | ||
| 'rounded-lg', | ||
| 'border', | ||
| 'hover:bg-gray-100', | ||
| 'dark:hover:bg-gray-800', | ||
| 'not-prose', | ||
| 'no-underline', | ||
| 'border-solid', | ||
| 'border', | ||
| 'hover:no-underline', | ||
| 'group' | ||
| )} | ||
| > | ||
| <div className={clsx('font-bold', 'group-hover:underline')}>{post.title}</div> | ||
|
|
||
| <p | ||
| className={clsx('font-sm')} | ||
| style={{ | ||
| display: '-webkit-box', | ||
| '-webkit-line-clamp': '3', | ||
| '-webkit-box-orient': 'vertical', | ||
| overflow: 'hidden', | ||
| 'text-overflow': 'ellipsis', | ||
| }} | ||
| > | ||
| {post.description} | ||
| </p> | ||
| </Link> | ||
| ))} | ||
| <p className="mb-4 p-0 text-xl"> | ||
| 🚀 Ready to build high-quality, scalable Prisma apps with built-in AuthZ and instant CRUD APIs ? | ||
| </p> | ||
| <Link className="mb-4 p-0 text-xl" to="/docs/welcome"> | ||
| Get started with ZenStack's ultimate guide to build faster and smarter | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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,78 @@ | ||
| const blogPluginExports = require('@docusaurus/plugin-content-blog'); | ||
| const utils = require('@docusaurus/utils'); | ||
| const path = require('path'); | ||
|
|
||
| const defaultBlogPlugin = blogPluginExports.default; | ||
| const MIN_RELATED_POSTS = 10; | ||
|
|
||
| function getMultipleRandomElement(arr, num) { | ||
| const shuffled = [...arr].sort(() => 0.5 - Math.random()); | ||
|
|
||
| return shuffled.slice(0, num); | ||
| } | ||
|
|
||
| function getRelatedPosts(allBlogPosts, metadata) { | ||
| const currentTags = new Set(metadata.frontMatter.tags?.filter((tag) => tag?.toLowerCase() != 'zenstack')); | ||
|
|
||
| let relatedPosts = allBlogPosts.filter( | ||
| (post) => | ||
| post.metadata.frontMatter.tags.some((tag) => currentTags.has(tag)) && post.metadata.title !== metadata.title | ||
| ); | ||
|
|
||
| if (relatedPosts.length < MIN_RELATED_POSTS) { | ||
| remainingCount = MIN_RELATED_POSTS - relatedPosts.length; | ||
| const remainingPosts = getMultipleRandomElement( | ||
| allBlogPosts.filter((post) => !relatedPosts.includes(post) && post.metadata.title !== metadata.title), | ||
| remainingCount | ||
| ); | ||
| relatedPosts = relatedPosts.concat(remainingPosts); | ||
| } | ||
|
|
||
| const filteredPostInfos = relatedPosts.map((post) => { | ||
| return { | ||
| title: post.metadata.title, | ||
| description: post.metadata.description, | ||
| permalink: post.metadata.permalink, | ||
| formattedDate: post.metadata.formattedDate, | ||
| authors: post.metadata.authors, | ||
| readingTime: post.metadata.readingTime, | ||
| date: post.metadata.date, | ||
| relatedWeight: post.metadata.frontMatter.tags.filter((tag) => currentTags.has(tag)).length * 3 + 1, | ||
| }; | ||
| }); | ||
|
|
||
| return filteredPostInfos; | ||
| } | ||
|
|
||
| async function blogPluginExtended(...pluginArgs) { | ||
| const blogPluginInstance = await defaultBlogPlugin(...pluginArgs); | ||
|
|
||
| return { | ||
| // Add all properties of the default blog plugin so existing functionality is preserved | ||
| ...blogPluginInstance, | ||
| contentLoaded: async function (data) { | ||
| await blogPluginInstance.contentLoaded(data); | ||
| const { content: blogContents, actions } = data; | ||
| const { blogPosts: allBlogPosts } = blogContents; | ||
| const { createData } = actions; | ||
| // Create routes for blog entries. | ||
| await Promise.all( | ||
| allBlogPosts.map(async (blogPost) => { | ||
| const { metadata } = blogPost; | ||
| const relatedPosts = getRelatedPosts(allBlogPosts, metadata); | ||
| await createData( | ||
| // Note that this created data path must be in sync with | ||
| // metadataPath provided to mdx-loader. | ||
| `${utils.docuHash(metadata.source)}.json`, | ||
| JSON.stringify({ ...metadata, relatedPosts }, null, 2) | ||
| ); | ||
| }) | ||
| ); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = { | ||
| ...blogPluginExports, | ||
| default: blogPluginExtended, | ||
| }; |
This file contains hidden or 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.
Clarify the transition to a plugin-based system.
The change to set the blog configuration to
falseis approved as it aligns with the transition to a plugin-based system. However, it would be beneficial to add a comment here explaining that the blog settings have been moved to a plugin to avoid confusion.Consider adding a comment for clarity:
Committable suggestion