Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added public/icons/morningbrew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions server/glob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const kuaishou: typeof import('./sources/kuaishou')
export const linuxdo: typeof import('./sources/linuxdo')
export const mktnews: typeof import('./sources/mktnews')
export const morningbrew: typeof import('./sources/morningbrew')
export const nowcoder: typeof import('./sources/nowcoder')
export const pcbeta: typeof import('./sources/pcbeta')
export const producthunt: typeof import('./sources/producthunt')
Expand Down
50 changes: 50 additions & 0 deletions server/sources/morningbrew.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { NewsItem } from "@shared/types"

const SANITY_QUERY = `
*[
_type == "newsletter.daily"
&& defined(slug.current)
&& defined(publishDate)
&& subjectLine.a != null
&& publishDate <= now()
] | order(publishDate desc)[0...30]{
"title": subjectLine.a,
"slug": slug.current,
"previewText": previewText,
"publishDate": publishDate
}
`.trim()

interface SanityIssue {
title: string
slug: string
previewText?: string
publishDate: string
}

interface SanityResponse {
result: SanityIssue[]
}

const fetchMorningBrew = defineSource(async () => {
const url = new URL("https://bl383u0v.apicdn.sanity.io/v2024-01-01/data/query/production")
url.searchParams.set("query", SANITY_QUERY)

const { result }: SanityResponse = await myFetch(url.toString())
if (!result?.length) throw new Error("Cannot fetch Morning Brew data")

return result.map((issue): NewsItem => ({
id: issue.slug,
title: issue.title.trim(),
url: `https://www.morningbrew.com/issues/${issue.slug}`,
pubDate: issue.publishDate,
extra: issue.previewText
? { hover: issue.previewText }
: undefined,
}))
})

export default defineSource({
"morningbrew": fetchMorningBrew,
"morningbrew-trending-today": fetchMorningBrew,
})
3 changes: 2 additions & 1 deletion shared/pinyin.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
"tencent-hot": "tengxunxinwen-zonghezaobao",
"freebuf": "Freebuf-wangluoanquan",
"qqvideo-tv-hotsearch": "tengxunshipin-resoubang",
"iqiyi-hot-ranklist": "aiqiyi-rebobang"
"iqiyi-hot-ranklist": "aiqiyi-rebobang",
"morningbrew-trending-today": "Morning Brew-Newsletter"
}
12 changes: 12 additions & 0 deletions shared/pre-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,18 @@ export const originSources = {
},
},
},
"morningbrew": {
name: "Morning Brew",
color: "blue",
home: "https://www.morningbrew.com",
column: "world",
sub: {
"trending-today": {
title: "Newsletter",
type: "realtime",
},
},
},
} as const satisfies Record<string, OriginSource>

export function genSources() {
Expand Down
19 changes: 19 additions & 0 deletions shared/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,5 +571,24 @@
"color": "green",
"interval": 1800000,
"title": "热播榜"
},
"morningbrew": {
"redirect": "morningbrew-trending-today",
"name": "Morning Brew",
"type": "realtime",
"column": "world",
"home": "https://www.morningbrew.com",
"color": "blue",
"interval": 600000,
"title": "Newsletter"
},
"morningbrew-trending-today": {
"name": "Morning Brew",
"type": "realtime",
"column": "world",
"home": "https://www.morningbrew.com",
"color": "blue",
"interval": 600000,
"title": "Newsletter"
}
}