-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/coinshift-support
- Loading branch information
Showing
220 changed files
with
9,216 additions
and
7,905 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,4 @@ out | |
|
||
# Next.js sitemap | ||
apps/cow-fi/public/robots.txt | ||
apps/cow-fi/public/sitemap* | ||
apps/cow-fi/public/sitemap* |
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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
{ | ||
"apps/cowswap-frontend": "1.90.0", | ||
"apps/explorer": "2.36.1", | ||
"libs/permit-utils": "0.4.0", | ||
"libs/widget-lib": "0.17.0", | ||
"apps/cowswap-frontend": "1.93.2", | ||
"apps/explorer": "2.38.0", | ||
"libs/permit-utils": "0.5.0", | ||
"libs/widget-lib": "0.18.0", | ||
"libs/widget-react": "0.11.0", | ||
"apps/widget-configurator": "1.9.0", | ||
"libs/analytics": "1.8.0", | ||
"libs/assets": "1.10.0", | ||
"libs/common-const": "1.10.1", | ||
"libs/common-hooks": "1.4.0", | ||
"libs/common-utils": "1.7.2", | ||
"libs/core": "1.3.0", | ||
"libs/ens": "1.2.0", | ||
"apps/widget-configurator": "1.10.0", | ||
"libs/analytics": "1.9.0", | ||
"libs/assets": "1.11.0", | ||
"libs/common-const": "1.12.2", | ||
"libs/common-hooks": "1.6.0", | ||
"libs/common-utils": "1.8.0", | ||
"libs/core": "1.5.0", | ||
"libs/ens": "1.3.0", | ||
"libs/events": "1.5.0", | ||
"libs/snackbars": "1.1.0", | ||
"libs/tokens": "1.11.0", | ||
"libs/types": "1.4.0", | ||
"libs/ui": "1.14.0", | ||
"libs/wallet": "1.6.1", | ||
"apps/cow-fi": "1.16.0", | ||
"libs/tokens": "1.13.0", | ||
"libs/types": "1.5.0", | ||
"libs/ui": "1.16.0", | ||
"libs/wallet": "1.7.0", | ||
"apps/cow-fi": "1.19.2", | ||
"libs/wallet-provider": "1.0.0", | ||
"libs/ui-utils": "1.1.0", | ||
"libs/abis": "1.2.0", | ||
"libs/balances-and-allowances": "1.1.1", | ||
"libs/balances-and-allowances": "1.2.0", | ||
"libs/iframe-transport": "1.0.0", | ||
"libs/hook-dapp-lib": "1.3.0", | ||
"libs/hook-dapp-lib": "1.4.0", | ||
"libs/multicall": "1.0.0" | ||
} |
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
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,5 @@ | ||
import { Layout } from '@/components/Layout' | ||
|
||
export default function LayoutPage({ children }: { children: React.ReactNode }) { | ||
return <Layout>{children}</Layout> | ||
} |
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,101 @@ | ||
'use server' | ||
|
||
import React from 'react' | ||
import { | ||
Article, | ||
getAllArticleSlugs, | ||
getArticleBySlug, | ||
getArticles, | ||
getCategories, | ||
SharedRichTextComponent, | ||
} from '../../../../services/cms' | ||
import { ArticlePageComponent } from '@/components/ArticlePageComponent' | ||
import { notFound } from 'next/navigation' | ||
import type { Metadata } from 'next' | ||
import { stripHtmlTags } from '@/util/stripHTMLTags' | ||
import { getPageMetadata } from '@/util/getPageMetadata' | ||
|
||
function isRichTextComponent(block: any): block is SharedRichTextComponent { | ||
return block.body !== undefined | ||
} | ||
|
||
type Props = { | ||
params: Promise<{ article: string }> | ||
} | ||
|
||
export async function generateMetadata({ params }: Props): Promise<Metadata> { | ||
const articleSlug = (await params).article | ||
|
||
if (!articleSlug) return {} | ||
|
||
const article = await getArticleBySlug(articleSlug) | ||
const attributes = article?.attributes | ||
const { title, blocks, description, cover } = attributes || {} | ||
const coverImageUrl = cover?.data?.attributes?.url | ||
|
||
const content = | ||
blocks?.map((block: SharedRichTextComponent) => (isRichTextComponent(block) ? block.body : '')).join(' ') || '' | ||
const plainContent = stripHtmlTags(content) | ||
|
||
return getPageMetadata({ | ||
absoluteTitle: `${title} - CoW DAO`, | ||
description: description | ||
? stripHtmlTags(description) | ||
: plainContent.length > 150 | ||
? stripHtmlTags(plainContent.substring(0, 147)) + '...' | ||
: stripHtmlTags(plainContent), | ||
image: coverImageUrl, | ||
}) | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const slugs = await getAllArticleSlugs() | ||
|
||
return slugs.map((article) => ({ article })) | ||
} | ||
|
||
export default async function ArticlePage({ params }: Props) { | ||
const articleSlug = (await params).article | ||
const article = await getArticleBySlug(articleSlug) | ||
|
||
if (!article) { | ||
return notFound() | ||
} | ||
|
||
const articlesResponse = await getArticles() | ||
const articles = articlesResponse.data | ||
|
||
// Fetch featured articles | ||
const featuredArticlesResponse = await getArticles({ | ||
filters: { | ||
featured: { | ||
$eq: true, | ||
}, | ||
}, | ||
pageSize: 7, // Limit to 7 articles | ||
}) | ||
const featuredArticles = featuredArticlesResponse.data | ||
|
||
const randomArticles = getRandomArticles(articles, 3) | ||
const categoriesResponse = await getCategories() | ||
const allCategories = | ||
categoriesResponse?.map((category: any) => ({ | ||
name: category?.attributes?.name || '', | ||
slug: category?.attributes?.slug || '', | ||
})) || [] | ||
|
||
return ( | ||
<ArticlePageComponent | ||
article={article} | ||
articles={articles} | ||
randomArticles={randomArticles} | ||
featuredArticles={featuredArticles} | ||
allCategories={allCategories} | ||
/> | ||
) | ||
} | ||
|
||
function getRandomArticles(articles: Article[], count: number): Article[] { | ||
const shuffled = articles.sort(() => 0.5 - Math.random()) | ||
return shuffled.slice(0, count) | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/layout.tsx
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,11 @@ | ||
import { Metadata } from 'next' | ||
import { getPageMetadata } from '@/util/getPageMetadata' | ||
|
||
export const metadata: Metadata = getPageMetadata({ | ||
title: 'All articles', | ||
description: 'All knowledge base articles in the Cow DAO ecosystem', | ||
}) | ||
|
||
export default function LayoutPage({ children }: { children: React.ReactNode }) { | ||
return children | ||
} |
67 changes: 67 additions & 0 deletions
67
apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/page.tsx
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,67 @@ | ||
'use server' | ||
|
||
import { Article, getArticles, getCategories } from '../../../../../services/cms' | ||
import { ArticlesPageComponents } from '@/components/ArticlesPageComponents' | ||
|
||
const ITEMS_PER_PAGE = 24 | ||
|
||
type Props = { | ||
params: Promise<{ pageIndex?: string }> | ||
} | ||
|
||
export type ArticlesResponse = { | ||
data?: Article[] | ||
meta?: { | ||
pagination?: { | ||
total?: number | ||
} | ||
} | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const articlesResponse = await getArticles({ page: 0, pageSize: ITEMS_PER_PAGE }) | ||
const totalArticles = articlesResponse.meta?.pagination?.total || 0 | ||
const totalPages = Math.ceil(totalArticles / ITEMS_PER_PAGE) | ||
|
||
return Array.from({ length: totalPages }, (_, i) => ({ pageIndex: [(i + 1).toString()] })) | ||
} | ||
|
||
export default async function Page({ params }: Props) { | ||
const pageParam = (await params)?.pageIndex | ||
const page = pageParam && pageParam.length > 0 ? parseInt(pageParam[0], 10) : 1 | ||
|
||
const articlesResponse = (await getArticles({ page, pageSize: ITEMS_PER_PAGE })) as ArticlesResponse | ||
|
||
const totalArticles = articlesResponse.meta?.pagination?.total || 0 | ||
const articles = | ||
articlesResponse.data?.map((article: Article) => ({ | ||
...article, | ||
id: article.id || 0, | ||
attributes: { | ||
...article.attributes, | ||
title: article.attributes?.title ?? 'Untitled', | ||
description: article.attributes?.description ?? '', | ||
slug: article.attributes?.slug ?? 'no-slug', | ||
featured: article.attributes?.featured ?? false, | ||
publishDateVisible: article.attributes?.publishDateVisible ?? false, | ||
cover: article.attributes?.cover ?? {}, | ||
blocks: article.attributes?.blocks ?? [], | ||
}, | ||
})) || [] | ||
|
||
const categoriesResponse = await getCategories() | ||
const allCategories = | ||
categoriesResponse?.map((category: any) => ({ | ||
name: category?.attributes?.name || '', | ||
slug: category?.attributes?.slug || '', | ||
})) || [] | ||
|
||
return ( | ||
<ArticlesPageComponents | ||
articles={articles} | ||
totalArticles={totalArticles} | ||
currentPage={page} | ||
allCategories={allCategories} | ||
/> | ||
) | ||
} |
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,20 @@ | ||
import { Metadata } from 'next' | ||
import { getPageMetadata } from '@/util/getPageMetadata' | ||
import { CONFIG } from '@/const/meta' | ||
|
||
const title = 'Knowledge Base - CoW DAO' | ||
|
||
export const metadata: Metadata = { | ||
...getPageMetadata({ | ||
title, | ||
description: CONFIG.description, | ||
}), | ||
title: { | ||
default: title, | ||
template: '%s - CoW DAO', | ||
}, | ||
} | ||
|
||
export default function LayoutPage({ children }: { children: React.ReactNode }) { | ||
return children | ||
} |
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,45 @@ | ||
'use server' | ||
|
||
import { getArticles, getCategories } from '../../../services/cms' | ||
|
||
import { LearnPageComponent } from '@/components/LearnPageComponent' | ||
|
||
export default async function Page() { | ||
const categoriesResponse = await getCategories() | ||
const articlesResponse = await getArticles() | ||
|
||
const featuredArticlesResponse = await getArticles({ | ||
filters: { featured: { $eq: true } }, | ||
pageSize: 6, | ||
}) | ||
|
||
const categories = | ||
categoriesResponse?.map((category: any) => { | ||
const imageUrl = category?.attributes?.image?.data?.attributes?.url || '' | ||
|
||
return { | ||
name: category?.attributes?.name || '', | ||
slug: category?.attributes?.slug || '', | ||
description: category?.attributes?.description || '', | ||
bgColor: category?.attributes?.backgroundColor || '#fff', | ||
textColor: category?.attributes?.textColor || '#000', | ||
link: `/learn/topic/${category?.attributes?.slug}`, | ||
iconColor: '#fff', | ||
imageUrl, | ||
} | ||
}) || [] | ||
|
||
const featuredArticles = featuredArticlesResponse.data.map((article) => { | ||
const attributes = article.attributes | ||
return { | ||
title: attributes?.title || 'No title', | ||
description: attributes?.description || 'No description', | ||
link: `/learn/${attributes?.slug || 'no-slug'}`, | ||
cover: attributes?.cover?.data?.attributes?.url || '', | ||
} | ||
}) | ||
|
||
return ( | ||
<LearnPageComponent categories={categories} articles={articlesResponse.data} featuredArticles={featuredArticles} /> | ||
) | ||
} |
Oops, something went wrong.