fix: migrate content

feat/collection
Arik Chakma 2 months ago
parent 8ccc8aa17d
commit 904ba51b7b
  1. 4
      scripts/generate-og-images.mjs
  2. 6
      src/components/FeaturedGuides.astro
  3. 28
      src/components/Questions/QuestionGuide.astro
  4. 3
      src/lib/question-group.ts
  5. 8
      src/pages/index.astro

@ -12,8 +12,8 @@ const ALL_BEST_PRACTICE_DIR = path.join(
process.cwd(), process.cwd(),
'/src/data/best-practices', '/src/data/best-practices',
); );
const ALL_GUIDE_DIR = path.join(process.cwd(), '/src/data/guides'); const ALL_GUIDE_DIR = path.join(process.cwd(), '/src/content/guides');
const ALl_AUTHOR_DIR = path.join(process.cwd(), '/src/data/authors'); const ALl_AUTHOR_DIR = path.join(process.cwd(), '/src/content/authors');
const ALL_ROADMAP_IMAGE_DIR = path.join(process.cwd(), '/public/roadmaps'); const ALL_ROADMAP_IMAGE_DIR = path.join(process.cwd(), '/public/roadmaps');
const ALL_BEST_PRACTICE_IMAGE_DIR = path.join( const ALL_BEST_PRACTICE_IMAGE_DIR = path.join(
process.cwd(), process.cwd(),

@ -1,7 +1,7 @@
--- ---
import type { GuideFileType } from '../lib/guide'; import type { GuideFileType } from '../lib/guide';
import GuideListItem from './GuideListItem.astro'; import GuideListItem from './GuideListItem.astro';
import { QuestionGroupType } from '../lib/question-group'; import type { QuestionGroupType } from '../lib/question-group';
export interface Props { export interface Props {
heading: string; heading: string;
@ -15,8 +15,8 @@ const sortedGuides: (QuestionGroupType | GuideFileType)[] = [
...guides, ...guides,
...questions, ...questions,
].sort((a, b) => { ].sort((a, b) => {
const aDate = new Date(a.frontmatter.date); const aDate = new Date(a.data.date!);
const bDate = new Date(b.frontmatter.date); const bDate = new Date(b.data.date!);
return bDate.getTime() - aDate.getTime(); return bDate.getTime() - aDate.getTime();
}); });

@ -1,13 +1,9 @@
--- ---
import { import { getGuideTableOfContent, type HeadingGroupType } from '../../lib/guide';
getGuideTableOfContent,
type GuideFileType,
HeadingGroupType,
} from '../../lib/guide';
import MarkdownFile from '../MarkdownFile.astro'; import MarkdownFile from '../MarkdownFile.astro';
import { TableOfContent } from '../TableOfContent/TableOfContent'; import { TableOfContent } from '../TableOfContent/TableOfContent';
import { markdownToHtml, replaceVariables } from '../../lib/markdown'; import { markdownToHtml, replaceVariables } from '../../lib/markdown';
import { QuestionGroupType } from '../../lib/question-group'; import type { QuestionGroupType } from '../../lib/question-group';
import { QuestionsList } from './QuestionsList'; import { QuestionsList } from './QuestionsList';
interface Props { interface Props {
@ -16,19 +12,17 @@ interface Props {
const { questionGroup } = Astro.props; const { questionGroup } = Astro.props;
const allHeadings = questionGroup.getHeadings(); const { headings: allHeadings, Content } = await questionGroup.render();
const tableOfContent: HeadingGroupType[] = [ const tableOfContent: HeadingGroupType[] = [
...getGuideTableOfContent(allHeadings), ...getGuideTableOfContent(allHeadings),
{ {
depth: 2, depth: 2,
title: 'Test with Flashcards', text: 'Test yourself with Flashcards',
children: [], children: [],
slug: 'test-with-flashcards', slug: 'test-with-flashcards',
text: 'Test yourself with Flashcards',
}, },
{ {
depth: 2, depth: 2,
title: 'Questions List',
children: [ children: [
{ {
depth: 2, depth: 2,
@ -58,7 +52,7 @@ const tableOfContent: HeadingGroupType[] = [
]; ];
const showTableOfContent = tableOfContent.length > 0; const showTableOfContent = tableOfContent.length > 0;
const { frontmatter: guideFrontmatter, author } = questionGroup; const { data: guideFrontmatter, author } = questionGroup;
--- ---
<article class='lg:grid lg:max-w-full lg:grid-cols-[1fr_minmax(0,700px)_1fr]'> <article class='lg:grid lg:max-w-full lg:grid-cols-[1fr_minmax(0,700px)_1fr]'>
@ -90,11 +84,11 @@ const { frontmatter: guideFrontmatter, author } = questionGroup;
class='inline-flex items-center font-medium underline-offset-2 hover:text-gray-600 hover:underline' class='inline-flex items-center font-medium underline-offset-2 hover:text-gray-600 hover:underline'
> >
<img <img
alt={author.frontmatter.name} alt={author.data.name}
src={author.frontmatter.imageUrl} src={author.data.imageUrl}
class='mb-0 mr-2 inline h-5 w-5 rounded-full' class='mb-0 mr-2 inline h-5 w-5 rounded-full'
/> />
{author.frontmatter.name} {author.data.name}
</a> </a>
<span class='mx-2 hidden sm:inline'>&middot;</span> <span class='mx-2 hidden sm:inline'>&middot;</span>
<a <a
@ -107,7 +101,7 @@ const { frontmatter: guideFrontmatter, author } = questionGroup;
</p> </p>
) )
} }
<questionGroup.Content /> <Content />
<h2 id='test-with-flashcards'>Test yourself with Flashcards</h2> <h2 id='test-with-flashcards'>Test yourself with Flashcards</h2>
<p> <p>
@ -136,8 +130,8 @@ const { frontmatter: guideFrontmatter, author } = questionGroup;
</h3> </h3>
{questionGroup.questions {questionGroup.questions
.filter((q) => { .filter((q) => {
return q.topics return q?.topics
.map((t) => t.toLowerCase()) ?.map((t) => t.toLowerCase())
.includes(questionLevel); .includes(questionLevel);
}) })
.map((q) => ( .map((q) => (

@ -1,5 +1,5 @@
import slugify from 'slugify'; import slugify from 'slugify';
import { getAllAuthors } from './author.ts'; import { getAllAuthors, type AuthorFileType } from './author.ts';
import { getCollection, type CollectionEntry } from 'astro:content'; import { getCollection, type CollectionEntry } from 'astro:content';
type RawQuestionGroupFileType = CollectionEntry<'question-groups'>; type RawQuestionGroupFileType = CollectionEntry<'question-groups'>;
@ -15,6 +15,7 @@ export type QuestionType = {
export type QuestionGroupType = RawQuestionGroupFileType & { export type QuestionGroupType = RawQuestionGroupFileType & {
questions: QuestionType[]; questions: QuestionType[];
allTopics: string[]; allTopics: string[];
author?: AuthorFileType;
}; };
/** /**

@ -23,11 +23,11 @@ const projectGroups = [
title: 'Backend', title: 'Backend',
id: 'backend', id: 'backend',
}, },
] ];
const guides = await getAllGuides(); const guides = await getAllGuides();
const questionGuides = (await getAllQuestionGroups()).filter( const questionGuides = (await getAllQuestionGroups()).filter(
(questionGroup) => questionGroup.frontmatter.authorId, (questionGroup) => questionGroup.data.authorId,
); );
const videos = await getAllVideos(); const videos = await getAllVideos();
--- ---
@ -92,9 +92,9 @@ const videos = await getAllVideos();
heading='Questions' heading='Questions'
allowBookmark={false} allowBookmark={false}
featuredItems={questionGroups.map((questionGroup) => ({ featuredItems={questionGroups.map((questionGroup) => ({
text: questionGroup.frontmatter.briefTitle, text: questionGroup.data.briefTitle,
url: `/questions/${questionGroup.id}`, url: `/questions/${questionGroup.id}`,
isNew: questionGroup.frontmatter.isNew, isNew: questionGroup.data.isNew,
}))} }))}
/> />

Loading…
Cancel
Save