Skip to content

Commit 12794dc

Browse files
authored
fix(cowfi): link featured articles with href (#5765)
* fix(cowfi): link featured articles with href * refactor(cowfi): replace Link with anchor tag for featured article sidebar
1 parent 8756853 commit 12794dc

File tree

5 files changed

+50
-49
lines changed

5 files changed

+50
-49
lines changed

apps/cow-fi/app/(learn)/learn/[article]/page.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ export default async function ArticlePage({ params }: Props) {
9292
return notFound()
9393
}
9494

95-
// Get related articles
96-
const articlesResponse = await getArticles()
97-
const articles = articlesResponse.data
98-
9995
// Fetch featured articles
10096
const featuredArticlesResponse = await getArticles({
10197
filters: {
@@ -107,7 +103,9 @@ export default async function ArticlePage({ params }: Props) {
107103
})
108104
const featuredArticles = featuredArticlesResponse.data
109105

110-
const randomArticles = getRandomArticles(articles, 3)
106+
// Get articles for random selection
107+
const allArticlesResponse = await getArticles()
108+
const randomArticles = getRandomArticles(allArticlesResponse.data, 3)
111109
const categoriesResponse = await getCategories()
112110
const allCategories =
113111
categoriesResponse?.map((category: any) => ({
@@ -118,7 +116,6 @@ export default async function ArticlePage({ params }: Props) {
118116
return (
119117
<ArticlePageComponent
120118
article={article}
121-
articles={articles}
122119
randomArticles={randomArticles}
123120
featuredArticles={featuredArticles}
124121
allCategories={allCategories}

apps/cow-fi/app/(learn)/learn/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { LearnPageComponent } from '@/components/LearnPageComponent'
2-
import { ARTICLES_LARGE_PAGE_SIZE, FEATURED_ARTICLES_PAGE_SIZE } from '@/const/pagination'
2+
import { FEATURED_ARTICLES_PAGE_SIZE } from '@/const/pagination'
33

44
import { getArticles, getCategories } from '../../../services/cms'
55

66
export const revalidate = 3600 // Revalidate at most once per hour
77

88
export default async function LearnPage() {
9-
const articlesResponse = await getArticles({ pageSize: ARTICLES_LARGE_PAGE_SIZE })
10-
const articles = articlesResponse.data
11-
129
// Fetch featured articles
1310
const featuredArticlesResponse = await getArticles({
1411
filters: {
@@ -48,5 +45,5 @@ export default async function LearnPage() {
4845
}
4946
}) || []
5047

51-
return <LearnPageComponent articles={articles} featuredArticles={featuredArticles} categories={categories} />
48+
return <LearnPageComponent featuredArticles={featuredArticles} categories={categories} />
5249
}

apps/cow-fi/components/ArticlePageComponent.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
'use client'
22

3-
import { Article, SharedRichTextComponent } from '../services/cms'
4-
import { stripHtmlTags } from '@/util/stripHTMLTags'
5-
import useWebShare from '../hooks/useWebShare'
3+
import { useMemo } from 'react'
4+
5+
import { useCowAnalytics } from '@cowprotocol/analytics'
6+
import { CmsImage, Color, Media } from '@cowprotocol/ui'
7+
8+
import ReactMarkdown from 'react-markdown'
9+
import rehypeRaw from 'rehype-raw'
10+
import styled from 'styled-components/macro'
11+
612
import { CategoryLinks } from '@/components/CategoryLinks'
13+
import { Link, LinkType } from '@/components/Link'
714
import { SearchBar } from '@/components/SearchBar'
815
import {
916
ArticleCard,
@@ -24,32 +31,22 @@ import {
2431
SectionTitleDescription,
2532
StickyMenu,
2633
} from '@/styles/styled'
27-
import { CowFiCategory } from 'src/common/analytics/types'
28-
import { Link, LinkType } from '@/components/Link'
29-
import { CmsImage, Color, Media } from '@cowprotocol/ui'
30-
import styled from 'styled-components/macro'
3134
import { formatDate } from '@/util/formatDate'
35+
import { stripHtmlTags } from '@/util/stripHTMLTags'
36+
import { CowFiCategory } from 'src/common/analytics/types'
37+
3238
import { useLazyLoadImages } from '../hooks/useLazyLoadImages'
33-
import { useMemo } from 'react'
34-
import ReactMarkdown from 'react-markdown'
35-
import rehypeRaw from 'rehype-raw'
36-
import { useCowAnalytics } from '@cowprotocol/analytics'
39+
import useWebShare from '../hooks/useWebShare'
40+
import { Article, SharedRichTextComponent } from '../services/cms'
3741

3842
interface ArticlePageProps {
3943
article: Article
40-
articles: Article[]
4144
randomArticles: Article[]
4245
featuredArticles: Article[]
4346
allCategories: { name: string; slug: string }[]
4447
}
4548

46-
export function ArticlePageComponent({
47-
articles,
48-
article,
49-
randomArticles,
50-
featuredArticles,
51-
allCategories,
52-
}: ArticlePageProps) {
49+
export function ArticlePageComponent({ article, randomArticles, featuredArticles, allCategories }: ArticlePageProps) {
5350
const attributes: {
5451
title?: string
5552
description?: string
@@ -183,7 +180,7 @@ export function ArticlePageComponent({
183180

184181
return (
185182
<li key={article.id}>
186-
<Link
183+
<a
187184
href={`/learn/${article.attributes?.slug}`}
188185
onClick={() =>
189186
analytics.sendEvent({
@@ -194,7 +191,7 @@ export function ArticlePageComponent({
194191
}
195192
>
196193
{articleTitle}
197-
</Link>
194+
</a>
198195
</li>
199196
)
200197
})}
@@ -322,7 +319,8 @@ function ArticleSharedRichTextComponent({ sharedRichText }: { sharedRichText: Sh
322319
return <LazyImage src={src} alt={alt || ''} {...props} width={725} height={400} />
323320
},
324321
}}
325-
children={processedContent}
326-
/>
322+
>
323+
{processedContent}
324+
</ReactMarkdown>
327325
)
328326
}

apps/cow-fi/components/LearnPageComponent.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
'use client'
22

3-
import { useLazyLoadImages } from '../hooks/useLazyLoadImages'
3+
import { useCowAnalytics } from '@cowprotocol/analytics'
4+
import IMG_ICON_BULB_COW from '@cowprotocol/assets/images/icon-bulb-cow.svg'
5+
import { Color, Font, Media } from '@cowprotocol/ui'
6+
7+
import styled from 'styled-components/macro'
8+
9+
import { ArrowButton } from '@/components/ArrowButton'
410
import { CategoryLinks } from '@/components/CategoryLinks'
11+
import LazySVG from '@/components/LazySVG'
512
import { SearchBar } from '@/components/SearchBar'
613
import {
714
ArticleCard,
@@ -27,15 +34,9 @@ import {
2734
TopicList,
2835
TopicTitle,
2936
} from '@/styles/styled'
30-
import { ArrowButton } from '@/components/ArrowButton'
31-
3237
import { CowFiCategory } from 'src/common/analytics/types'
33-
import { Color, Font, Media } from '@cowprotocol/ui'
34-
import LazySVG from '@/components/LazySVG'
35-
import IMG_ICON_BULB_COW from '@cowprotocol/assets/images/icon-bulb-cow.svg'
36-
import { ArticleListResponse } from '../services/cms'
37-
import styled from 'styled-components/macro'
38-
import { useCowAnalytics } from '@cowprotocol/analytics'
38+
39+
import { useLazyLoadImages } from '../hooks/useLazyLoadImages'
3940

4041
const PODCASTS = [
4142
{
@@ -114,7 +115,6 @@ interface PageProps {
114115
iconColor: string
115116
imageUrl: string
116117
}[]
117-
articles: ArticleListResponse['data']
118118
featuredArticles: {
119119
title: string
120120
description: string
@@ -156,7 +156,7 @@ const Wrapper = styled.div`
156156
}
157157
`
158158

159-
export function LearnPageComponent({ categories, articles, featuredArticles }: PageProps) {
159+
export function LearnPageComponent({ categories, featuredArticles }: PageProps) {
160160
const { LazyImage } = useLazyLoadImages()
161161
const analytics = useCowAnalytics()
162162

@@ -181,6 +181,8 @@ export function LearnPageComponent({ categories, articles, featuredArticles }: P
181181
<ArticleCard
182182
key={index}
183183
href={link}
184+
target="_blank"
185+
rel="noopener noreferrer"
184186
onClick={() =>
185187
analytics.sendEvent({
186188
category: CowFiCategory.KNOWLEDGEBASE,

apps/cow-fi/styles/styled.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import styled, { css } from 'styled-components/macro'
21
import { Font, Color, Media } from '@cowprotocol/ui'
2+
33
import { transparentize } from 'color2k'
4+
import styled, { css } from 'styled-components/macro'
5+
46
import { PAGE_MAX_WIDTH } from '@/components/Layout/const'
5-
import Link from 'next/link'
67

78
export const PageWrapper = styled.div<{ margin?: string }>`
89
display: flex;
@@ -133,13 +134,19 @@ export const ArticleList = styled.div<{ columns?: number; columnsTablet?: number
133134
}
134135
`
135136

136-
export const ArticleCard = styled(Link)`
137+
export const ArticleCard = styled.a`
137138
display: flex;
138139
flex-direction: column;
139-
padding: 0;
140+
padding: 1.2rem;
140141
border-radius: 2rem;
141142
width: 100%;
142143
text-decoration: none;
144+
background: transparent;
145+
transition: background 0.2s ease-in-out;
146+
147+
&:hover {
148+
background: ${Color.neutral98};
149+
}
143150
`
144151

145152
export const ArticleImage = styled.div<{ color?: string }>`

0 commit comments

Comments
 (0)