updated to astro v3.6

This commit is contained in:
somrat sorkar
2023-12-03 15:28:12 +06:00
parent 34e3ac525f
commit afb57b5825
22 changed files with 151 additions and 121 deletions
+9 -6
View File
@@ -1,23 +1,26 @@
---
import BlogCard from "@/components/BlogCard.astro";
import Share from "@/components/Share.astro";
import config from "@/config/config.json";
import Disqus from "@/helpers/Disqus";
import { getSinglePage } from "@/lib/contentParser.astro";
import dateFormat from "@/lib/utils/dateFormat";
import similerItems from "@/lib/utils/similarItems";
import similarItems from "@/lib/utils/similarItems";
import { humanize, markdownify, slugify } from "@/lib/utils/textConverter";
import { Image } from "astro:assets";
import { getCollection } from "astro:content";
import {
FaRegClock,
FaRegFolder,
FaRegUserCircle,
} from "react-icons/fa/index.js";
const { blog_folder } = config.settings;
const posts = await getSinglePage(blog_folder);
const COLLECTION_FOLDER = "blog";
const { post } = Astro.props;
const similarPosts = similerItems(post, posts, post.slug);
const posts = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const similarPosts = similarItems(post, posts);
const { Content } = await post.render();
const { title, description, author, categories, image, date, tags } = post.data;
---
+2 -2
View File
@@ -25,7 +25,7 @@ interface SearchResult {
refIndex: number;
}
const Search = ({ searchList }: Props) => {
const SearchLayout = ({ searchList }: Props) => {
const inputRef = useRef<HTMLInputElement>(null);
const [inputVal, setInputVal] = useState("");
const [searchResults, setSearchResults] = useState<SearchResult[]>([]);
@@ -178,4 +178,4 @@ const Search = ({ searchList }: Props) => {
);
};
export default Search;
export default SearchLayout;
+1 -1
View File
@@ -20,7 +20,7 @@ export interface ISocial {
rel="noopener noreferrer nofollow"
>
<span class="sr-only">{social.name}</span>
<DynamicIcon class="inline-block" icon={social.icon} />
<DynamicIcon className="inline-block" icon={social.icon} />
</a>
</li>
))
+1 -1
View File
@@ -1,4 +1,4 @@
import React, { FC } from "react";
import React, { type FC } from "react";
import type { IconType } from "react-icons";
import * as FaIcons from "react-icons/fa6/index.js";
// import * as AiIcons from "react-icons/ai/index.js";
-10
View File
@@ -1,10 +0,0 @@
---
import { getCollection } from "astro:content";
export const getSinglePage = async (collection: any) => {
const allPage = await getCollection(collection);
const removeIndex = allPage.filter((data: any) => data.id.match(/^(?!-)/));
const removeDrafts = removeIndex.filter((data: any) => !data.data.draft);
return removeDrafts;
};
---
+11 -2
View File
@@ -1,8 +1,16 @@
---
import { getSinglePage } from "./contentParser.astro";
import { getCollection } from "astro:content";
import { slugify } from "./utils/textConverter";
// get all taxonomies from frontmatter
// get all pages from collection
export const getSinglePage = async (collection: any) => {
const allPage = await getCollection(collection);
const removeIndex = allPage.filter((data: any) => data.id.match(/^(?!-)/));
const removeDrafts = removeIndex.filter((data: any) => !data.data.draft);
return removeDrafts;
};
// get taxonomy from frontmatter
export const getTaxonomy = async (collection: string, name: string) => {
const singlePages = await getSinglePage(collection);
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
@@ -17,6 +25,7 @@ export const getTaxonomy = async (collection: string, name: string) => {
return taxonomy;
};
// get all taxonomies from frontmatter
export const getAllTaxonomy = async (collection: string, name: string) => {
const singlePages = await getSinglePage(collection);
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
+6 -4
View File
@@ -1,5 +1,5 @@
// similer products
const similerItems = (currentItem: any, allItems: any, slug: string) => {
// similar products
const similarItems = (currentItem: any, allItems: any[]) => {
let categories: string[] = [];
let tags: string[] = [];
@@ -27,9 +27,11 @@ const similerItems = (currentItem: any, allItems: any, slug: string) => {
const mergedItems = [...new Set([...filterByCategories, ...filterByTags])];
// filter by slug
const filterBySlug = mergedItems.filter((product) => product.slug !== slug);
const filterBySlug = mergedItems.filter(
(product) => product.slug !== currentItem.slug,
);
return filterBySlug;
};
export default similerItems;
export default similarItems;
+7 -2
View File
@@ -1,10 +1,15 @@
---
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import PageHeader from "@/partials/PageHeader.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const pages = await getSinglePage("pages");
const COLLECTION_FOLDER = "pages";
const pages = await getCollection(
COLLECTION_FOLDER,
({ data }) => !data.draft,
);
const paths = pages.map((page) => ({
params: {
+10 -5
View File
@@ -1,14 +1,17 @@
---
import BlogCard from "@/components/BlogCard.astro";
import Social from "@/components/Social.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { slugify } from "@/lib/utils/textConverter";
import { Image } from "astro:assets";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const authors = await getSinglePage("authors");
const COLLECTION_FOLDER = "authors";
const authors = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const paths = authors.map((author) => ({
params: {
@@ -19,11 +22,13 @@ export async function getStaticPaths() {
return paths;
}
const { blog_folder }: { blog_folder: string } = config.settings;
const { author } = Astro.props;
const { title, social, meta_title, description, image } = author.data;
const { Content } = await author.render();
const posts = await getSinglePage(blog_folder);
const posts = await getCollection(
"blog",
({ data, slug }) => !data.draft && slug !== "-index",
);
const postFilterByAuthor = posts.filter(
(post) => slugify(post.data.author) === slugify(title),
);
+8 -4
View File
@@ -1,12 +1,16 @@
---
import AuthorCard from "@/components/AuthorCard.astro";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import PageHeader from "@/partials/PageHeader.astro";
import { getEntry } from "astro:content";
import { getCollection, getEntry } from "astro:content";
const authorIndex = await getEntry<any, string>("authors", "-index");
const authors = await getSinglePage("authors");
const COLLECTION_FOLDER = "authors";
const authorIndex = await getEntry(COLLECTION_FOLDER, "-index");
const authors = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
---
<Base title={authorIndex.data.title}>
+6 -3
View File
@@ -1,11 +1,14 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import PostSingle from "@/layouts/PostSingle.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const posts = await getSinglePage(config.settings.blog_folder);
const COLLECTION_FOLDER = "blog";
const posts = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const paths = posts.map((post) => ({
params: {
+12 -9
View File
@@ -3,19 +3,22 @@ import BlogCard from "@/components/BlogCard.astro";
import Pagination from "@/components/Pagination.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { sortByDate } from "@/lib/utils/sortFunctions";
import PageHeader from "@/partials/PageHeader.astro";
import PostSidebar from "@/partials/PostSidebar.astro";
import { getEntry } from "astro:content";
import { getCollection, getEntry } from "astro:content";
const { blog_folder } = config.settings;
const postIndex = await getEntry<any, string>(blog_folder, "-index");
const posts = await getSinglePage(blog_folder);
const allCategories = await getAllTaxonomy(blog_folder, "categories");
const categories = await getTaxonomy(blog_folder, "categories");
const tags = await getTaxonomy(blog_folder, "tags");
const COLLECTION_FOLDER = "blog";
const postIndex = await getEntry(COLLECTION_FOLDER, "-index");
const posts = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const allCategories = await getAllTaxonomy(COLLECTION_FOLDER, "categories");
const categories = await getTaxonomy(COLLECTION_FOLDER, "categories");
const tags = await getTaxonomy(COLLECTION_FOLDER, "tags");
const sortedPosts = sortByDate(posts);
const totalPages: number = Math.ceil(posts.length / config.settings.pagination);
const currentPosts = sortedPosts.slice(0, config.settings.pagination);
@@ -43,7 +46,7 @@ const currentPosts = sortedPosts.slice(0, config.settings.pagination);
}
</div>
<Pagination
section={blog_folder}
section={COLLECTION_FOLDER}
currentPage={1}
totalPages={totalPages}
/>
+17 -10
View File
@@ -3,20 +3,23 @@ import BlogCard from "@/components/BlogCard.astro";
import Pagination from "@/components/Pagination.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { sortByDate } from "@/lib/utils/sortFunctions";
import PageHeader from "@/partials/PageHeader.astro";
import PostSidebar from "@/partials/PostSidebar.astro";
import { getEntry } from "astro:content";
import { getCollection, getEntry } from "astro:content";
const COLLECTION_FOLDER = "blog";
const { blog_folder } = config.settings;
const { slug } = Astro.params;
const postIndex = await getEntry<any, string>(blog_folder, "-index");
const posts = await getSinglePage(blog_folder);
const allCategories = await getAllTaxonomy(blog_folder, "categories");
const categories = await getTaxonomy(blog_folder, "categories");
const tags = await getTaxonomy(blog_folder, "tags");
const postIndex = await getEntry(COLLECTION_FOLDER, "-index");
const posts = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const allCategories = await getAllTaxonomy(COLLECTION_FOLDER, "categories");
const categories = await getTaxonomy(COLLECTION_FOLDER, "categories");
const tags = await getTaxonomy(COLLECTION_FOLDER, "tags");
const sortedPosts = sortByDate(posts);
const totalPages = Math.ceil(posts.length / config.settings.pagination);
const currentPage = slug && !isNaN(Number(slug)) ? Number(slug) : 1;
@@ -25,7 +28,11 @@ const indexOfFirstPost = indexOfLastPost - config.settings.pagination;
const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost);
export async function getStaticPaths() {
const posts = await getSinglePage(config.settings.blog_folder);
const COLLECTION_FOLDER = "blog";
const posts = await getCollection(
COLLECTION_FOLDER,
({ data, slug }) => !data.draft && slug !== "-index",
);
const totalPages = Math.ceil(posts.length / config.settings.pagination);
const paths = [];
@@ -62,7 +69,7 @@ export async function getStaticPaths() {
}
</div>
<Pagination
section={blog_folder}
section={COLLECTION_FOLDER}
currentPage={currentPage}
totalPages={totalPages}
/>
+7 -7
View File
@@ -1,17 +1,14 @@
---
import BlogCard from "@/components/BlogCard.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
import PageHeader from "@/partials/PageHeader.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const categories = await getTaxonomy(
config.settings.blog_folder,
"categories"
);
const BLOG_FOLDER = "blog";
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
return categories.map((category) => {
return {
@@ -21,7 +18,10 @@ export async function getStaticPaths() {
}
const { category } = Astro.params;
const posts = await getSinglePage(config.settings.blog_folder);
const posts = await getCollection(
"blog",
({ data, slug }) => !data.draft && slug !== "-index",
);
const filterByCategories = taxonomyFilter(posts, "categories", category!);
---
+4 -4
View File
@@ -1,13 +1,13 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { humanize } from "@/lib/utils/textConverter";
import PageHeader from "@/partials/PageHeader.astro";
const { blog_folder }: { blog_folder: string } = config.settings;
const categories = await getTaxonomy(blog_folder, "categories");
const allCategories = await getAllTaxonomy(blog_folder, "categories");
const BLOG_FOLDER = "blog";
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
const allCategories = await getAllTaxonomy(BLOG_FOLDER, "categories");
---
<Base title={"Categories"}>
+7 -8
View File
@@ -1,13 +1,12 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import Search from "@/layouts/Search";
import { getSinglePage } from "@/lib/contentParser.astro";
import SearchLayout from "@/layouts/Search";
import { getCollection } from "astro:content";
const { blog_folder } = config.settings;
// Retrieve all articles
const posts = await getSinglePage(blog_folder);
const posts = await getCollection(
"blog",
({ data, slug }) => !data.draft && slug !== "-index",
);
// List of items to search in
const searchList = posts.map((item) => ({
@@ -18,5 +17,5 @@ const searchList = posts.map((item) => ({
---
<Base title={`Search`}>
<Search client:load searchList={searchList} />
<SearchLayout client:load searchList={searchList} />
</Base>
+9 -6
View File
@@ -1,14 +1,14 @@
---
import BlogCard from "@/components/BlogCard.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro";
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
import PageHeader from "@/partials/PageHeader.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const tags = await getTaxonomy(config.settings.blog_folder, "tags");
const BLOG_FOLDER = "blog";
const tags = await getTaxonomy(BLOG_FOLDER, "tags");
return tags.map((tag) => {
return {
@@ -18,8 +18,11 @@ export async function getStaticPaths() {
}
const { tag } = Astro.params;
const posts = await getSinglePage(config.settings.blog_folder);
const filterByCategories = taxonomyFilter(posts, "tags", tag!);
const posts = await getCollection(
"blog",
({ data, slug }) => !data.draft && slug !== "-index",
);
const filterByTags = taxonomyFilter(posts, "categories", tag!);
---
<Base title={tag}>
@@ -28,7 +31,7 @@ const filterByCategories = taxonomyFilter(posts, "tags", tag!);
<div class="container">
<div class="row">
{
filterByCategories.map((post) => (
filterByTags.map((post) => (
<div class="mb-14 md:col-6 lg:col-4">
<BlogCard data={post} />
</div>
+4 -4
View File
@@ -1,13 +1,13 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { humanize } from "@/lib/utils/textConverter";
import PageHeader from "@/partials/PageHeader.astro";
const { blog_folder }: { blog_folder: string } = config.settings;
const tags = await getTaxonomy(blog_folder, "tags");
const allTags = await getAllTaxonomy(blog_folder, "tags");
const BLOG_FOLDER = "blog";
const tags = await getTaxonomy(BLOG_FOLDER, "tags");
const allTags = await getAllTaxonomy(BLOG_FOLDER, "tags");
---
<Base title={"Tags"}>