Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate resources #408

Merged
merged 20 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions .github/scripts/getResourcesOg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const ogs = require('open-graph-scraper')
const fs = require('fs')
const path = require('path')

const resourcesPath = './components/ResourceHub/company-resources.json'
const communityResourcesPath =
Expand All @@ -19,37 +18,35 @@ const updateResourceOg = async () => {
)

const updatedResources = await Promise.all(
resources
.filter(r => r.type !== 'video')
.map(async resource => {
const og = await getResourceOg(resource.url)
return {
...resource,
og: {
title: og.ogTitle,
description: og.ogDescription,
image: og.ogImage[0]?.url
}
}
})
resources.map(async resource => {
const og = await getResourceOg(resource.url)
return {
name: resource.name ?? og.ogTitle,
url: resource.url,
type: resource.type,
date: resource.date,
description: resource.description ?? og.ogDescription,
tags: resource.tags,
image: og.ogImage[0]?.url
}
})
)

const updatedCommunityResources = await Promise.all(
communityResources
.filter(r => r.type !== 'video')
.map(async resource => {
const og = await getResourceOg(resource.url)
return {
...resource,
og: {
title: og.ogTitle,
description: og.ogDescription,
...(!(parseInt(og.ogImage[0].height) < 60) && {
image: og.ogImage[0].url
})
}
}
})
communityResources.map(async resource => {
const og = await getResourceOg(resource.url)
return {
name: resource.name ?? og.ogTitle,
url: resource.url,
type: resource.type,
date: resource.date,
description: resource.description ?? og.ogDescription,
tags: resource.tags,
...(!(parseInt(og.ogImage[0].height) < 60) && {
image: og.ogImage[0].url
})
}
})
)

fs.writeFileSync(resourcesPath, JSON.stringify(updatedResources, null, 2))
Expand Down
54 changes: 54 additions & 0 deletions .github/scripts/validateResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const fs = require('fs')

const resourcesPath = './components/ResourceHub/company-resources.json'
const communityResourcesPath =
'./components/ResourceHub/community-resources.json'

const validateResource = (resource, index, resources) => {
if (resources.findIndex(r => r.url === resource.url) !== index) {
console.log(`Duplicate resource`)
return false
}
if (!resource.name) {
console.log(`Resource name is missing`)
return false
}
if (!resource.type) {
console.log(`Resource type is missing`)
return false
}
if (!resource.date) {
console.log(`Resource date is missing`)
return false
}
if (!resource.description) {
console.log(`Resource description is missing`)
return false
}
if (!resource.tags || !resource.tags.length) {
console.log(errorMessage + `Resource tags are missing`)
return false
}
if (
resource.url.includes('youtube') &&
(!resource.url.startsWith('https://www.youtube.com/watch?v=') ||
resource.url.length !== 43)
) {
console.log(`Invalid YouTube URL`)
return false
}
return true
}

const validateResources = () => {
const resources = [
...JSON.parse(fs.readFileSync(resourcesPath, 'utf8')),
...JSON.parse(fs.readFileSync(communityResourcesPath, 'utf8'))
]

if (resources.map(validateResource).some(valid => !valid)) {
process.exit(1)
}
}

validateResources()
4 changes: 2 additions & 2 deletions .github/workflows/generate-supported-networks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Use Node.js 20.x
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '20.x'
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions components/ResourceHub/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export const ProjectCard = (resource: KnowledgeResource): JSX.Element => {
<div style={{ width: '100%' }}>
{resource.type === 'Video' ? (
<YouTubeEmbed embedId={resource.url.slice(-11)} />
) : resource?.og?.image == null ? (
) : resource?.image == null ? (
resource.type === 'Blog Post' ? (
<Blog />
) : (
<Podcast />
)
) : (
<Box minHeight='100px'>
<img alt='resource-img' src={resource.og.image} />
<img alt='resource-img' src={resource.image} />
</Box>
)}

Expand All @@ -80,7 +80,7 @@ export const ProjectCard = (resource: KnowledgeResource): JSX.Element => {
color='text.secondary'
className={css.description}
>
{resource.abstract}
{resource.description}
</Typography>
</>
)}
Expand Down
8 changes: 2 additions & 6 deletions components/ResourceHub/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ export interface KnowledgeResource {
type: string
date: string
origin: string
abstract?: string
description: string
tags: string[]
og?: {
title?: string
description?: string
image?: string
}
image?: string
}

const getUniqueStrings = (entries: string[]): string[] => {
Expand Down
Loading
Loading