rename index file for collection and added accessiblity for some components

This commit is contained in:
somrat sorkar
2023-05-15 12:19:03 +06:00
parent 60c98d631b
commit cc0e52e48b
11 changed files with 53 additions and 32 deletions
+5
View File
@@ -0,0 +1,5 @@
---
title: "Authors"
meta_title: ""
description: "this is meta description"
---
-3
View File
@@ -1,3 +0,0 @@
---
title: "Authors"
---
+1 -1
View File
@@ -48,6 +48,6 @@ const pagesCollection = defineCollection({
// Export collections // Export collections
export const collections = { export const collections = {
posts: postsCollection, posts: postsCollection,
pages: pagesCollection,
authors: authorsCollection, authors: authorsCollection,
pages: pagesCollection,
}; };
+2 -2
View File
@@ -13,7 +13,7 @@ const Accordion = ({
return ( return (
<div className={`accordion ${show && "active"} ${className}`}> <div className={`accordion ${show && "active"} ${className}`}>
<div className="accordion-header" onClick={() => setShow(!show)}> <button className="accordion-header" onClick={() => setShow(!show)}>
{title} {title}
<svg <svg
className="accordion-icon" className="accordion-icon"
@@ -27,7 +27,7 @@ const Accordion = ({
d="M505.755,123.592c-8.341-8.341-21.824-8.341-30.165,0L256.005,343.176L36.421,123.592c-8.341-8.341-21.824-8.341-30.165,0 s-8.341,21.824,0,30.165l234.667,234.667c4.16,4.16,9.621,6.251,15.083,6.251c5.462,0,10.923-2.091,15.083-6.251l234.667-234.667 C514.096,145.416,514.096,131.933,505.755,123.592z" d="M505.755,123.592c-8.341-8.341-21.824-8.341-30.165,0L256.005,343.176L36.421,123.592c-8.341-8.341-21.824-8.341-30.165,0 s-8.341,21.824,0,30.165l234.667,234.667c4.16,4.16,9.621,6.251,15.083,6.251c5.462,0,10.923-2.091,15.083-6.251l234.667-234.667 C514.096,145.416,514.096,131.933,505.755,123.592z"
></path> ></path>
</svg> </svg>
</div> </button>
<div className="accordion-content">{children}</div> <div className="accordion-content">{children}</div>
</div> </div>
); );
+39 -20
View File
@@ -1,44 +1,63 @@
import { marked } from "marked"; import { marked } from "marked";
import React, { useState } from "react"; import React, { useEffect, useRef, useState } from "react";
function Tabs({ children }: { children: any }) { const Tabs = ({ children }: any) => {
const [active, setAvtive] = useState(0); const [active, setActive] = useState(0);
const [defaultFocus, setDefaultFocus] = useState(false);
const tabItems = Array.from( const tabRefs: any = useRef([]);
useEffect(() => {
if (defaultFocus) {
tabRefs.current[active]?.focus();
} else {
setDefaultFocus(true);
}
}, [active]);
const tabLinks = Array.from(
children.props.value.matchAll( children.props.value.matchAll(
/<div\s+data-name="([^"]+)"[^>]*>(.*?)<\/div>/gs /<div\s+data-name="([^"]+)"[^>]*>(.*?)<\/div>/gs
), ),
(match: RegExpMatchArray) => ({ name: match[1], children: match[0] }) (match: RegExpMatchArray) => ({ name: match[1], children: match[0] })
); );
const handleKeyDown = (event: any, index: number) => {
if (event.key === "Enter" || event.key === " ") {
setActive(index);
} else if (event.key === "ArrowRight") {
setActive((active + 1) % tabLinks.length);
} else if (event.key === "ArrowLeft") {
setActive((active - 1 + tabLinks.length) % tabLinks.length);
}
};
return ( return (
<div className="tab"> <div className="tab">
<ul className="tab-nav"> <ul className="tab-nav">
{tabItems.map((item: any, index: number) => ( {tabLinks.map((item: any, index: number) => (
<li <li
key={index} key={index}
className={`tab-nav-item ${index === active && "active"}`} className={`tab-nav-item ${index === active && "active"}`}
onClick={() => setAvtive(index)} role="tab"
tabIndex={index === active ? 0 : -1}
onKeyDown={(event) => handleKeyDown(event, index)}
onClick={() => setActive(index)}
ref={(ref) => (tabRefs.current[index] = ref)}
> >
{item.name} {item.name}
</li> </li>
))} ))}
</ul> </ul>
{tabLinks.map((item, i) => (
<div className="tab-content"> <div
{tabItems.map((item, i) => ( className={active === i ? "tab-content block px-5" : "hidden"}
<div dangerouslySetInnerHTML={{
className={`tab-content-panel ${ __html: marked.parseInline(item.children),
active === i ? "active" : "hidden" }}
}`} />
dangerouslySetInnerHTML={{ ))}
__html: marked.parse(item.children),
}}
/>
))}
</div>
</div> </div>
); );
} };
export default Tabs; export default Tabs;
+1 -1
View File
@@ -3,7 +3,7 @@ import { getCollection } from "astro:content";
export const getSinglePage = async (collection: any) => { export const getSinglePage = async (collection: any) => {
const allPage = await getCollection(collection); const allPage = await getCollection(collection);
const removeIndex = allPage.filter((data) => data.id !== "index.md"); const removeIndex = allPage.filter((data) => data.id.match(/^(?!-)/));
const removeDrafts = removeIndex.filter((data) => !data.data.draft); const removeDrafts = removeIndex.filter((data) => !data.data.draft);
return removeDrafts; return removeDrafts;
}; };
+1 -1
View File
@@ -5,7 +5,7 @@ import { getSinglePage } from "@/lib/contentParser.astro";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import { getEntryBySlug } from "astro:content"; import { getEntryBySlug } from "astro:content";
const authorIndex = await getEntryBySlug<any, string>("authors", "index"); const authorIndex = await getEntryBySlug<any, string>("authors", "-index");
const authors = await getSinglePage("authors"); const authors = await getSinglePage("authors");
--- ---
+1 -1
View File
@@ -11,7 +11,7 @@ import PostSidebar from "@/partials/PostSidebar.astro";
import { getEntryBySlug } from "astro:content"; import { getEntryBySlug } from "astro:content";
const { blog_folder } = config.settings; const { blog_folder } = config.settings;
const postIndex = await getEntryBySlug<any, string>(blog_folder, "index"); const postIndex = await getEntryBySlug<any, string>(blog_folder, "-index");
const posts = await getSinglePage(blog_folder); const posts = await getSinglePage(blog_folder);
const allCategories = await getAllTaxonomy(blog_folder, "categories"); const allCategories = await getAllTaxonomy(blog_folder, "categories");
const categories = await getTaxonomy(blog_folder, "categories"); const categories = await getTaxonomy(blog_folder, "categories");
+1 -1
View File
@@ -12,7 +12,7 @@ import { getEntryBySlug } from "astro:content";
const { blog_folder } = config.settings; const { blog_folder } = config.settings;
const { slug } = Astro.params; const { slug } = Astro.params;
const postIndex = await getEntryBySlug<any, string>(blog_folder, "index"); const postIndex = await getEntryBySlug<any, string>(blog_folder, "-index");
const posts = await getSinglePage(blog_folder); const posts = await getSinglePage(blog_folder);
const allCategories = await getAllTaxonomy(blog_folder, "categories"); const allCategories = await getAllTaxonomy(blog_folder, "categories");
const categories = await getTaxonomy(blog_folder, "categories"); const categories = await getTaxonomy(blog_folder, "categories");
+2 -2
View File
@@ -118,10 +118,10 @@
.accordion { .accordion {
@apply mb-6 overflow-hidden rounded-lg border border-border bg-theme-light dark:border-darkmode-border dark:bg-darkmode-theme-light; @apply mb-6 overflow-hidden rounded-lg border border-border bg-theme-light dark:border-darkmode-border dark:bg-darkmode-theme-light;
&-header { &-header {
@apply flex cursor-pointer items-center justify-between px-8 py-4 text-lg text-dark dark:bg-darkmode-theme-light dark:text-darkmode-light; @apply flex w-full cursor-pointer items-center justify-between px-8 py-4 text-lg text-dark dark:bg-darkmode-theme-light dark:text-darkmode-light;
} }
&-icon { &-icon {
@apply h-[.8em] w-[.8em] rotate-[-90deg] transition-transform duration-200; @apply ml-auto h-[.8em] w-[.8em] rotate-[-90deg] transition-transform duration-200;
} }
&-content { &-content {
@apply max-h-0 overflow-hidden px-8 py-0; @apply max-h-0 overflow-hidden px-8 py-0;