Skip to content

Commit

Permalink
feat(route): daily.dev sources
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Nov 5, 2024
1 parent 7ea07bc commit d676831
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 113 deletions.
2 changes: 1 addition & 1 deletion lib/routes/buaa/lib/space/newbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import cache from '@/utils/cache';
import { art } from '@/utils/render';
import path from 'path';
import path from 'node:path';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

Expand Down
43 changes: 22 additions & 21 deletions lib/routes/daily/discussed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Route } from '@/types';
import { getData, getList, getRedirectedLink } from './utils.js';

const variables = {
first: 15,
};
import { baseUrl, getData, getList } from './utils.js';

const query = `
query MostDiscussedFeed(
Expand All @@ -19,6 +15,7 @@ const query = `
edges {
node {
...FeedPost
contentHtml
}
}
}
Expand All @@ -33,6 +30,7 @@ const query = `
image
readTime
permalink
commentsPermalink
summary
createdAt
numUpvotes
Expand All @@ -52,37 +50,40 @@ const query = `
bio
}
`;
const graphqlQuery = {
query,
variables,
};

export const route: Route = {
path: '/discussed',
example: '/daily/discussed',
radar: [
{
source: ['daily.dev/popular'],
source: ['app.daily.dev/discussed'],
},
],
name: 'Most Discussed',
maintainers: ['Rjnishant530'],
handler,
url: 'daily.dev/popular',
url: 'app.daily.dev/discussed',
};

async function handler() {
const baseUrl = 'https://app.daily.dev/discussed';
const data = await getData(graphqlQuery);
const list = getList(data);
const items = await getRedirectedLink(list);
async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20;
const link = `${baseUrl}/discussed`;

const data = await getData({
query,
variables: {
first: limit,
},
});
const items = getList(data);

return {
title: 'Most Discussed',
link: baseUrl,
title: 'Real-time discussions in the developer community | daily.dev',
link,
item: items,
description: 'Most Discussed Posts on Daily.dev',
logo: 'https://app.daily.dev/favicon-32x32.png',
icon: 'https://app.daily.dev/favicon-32x32.png',
description: 'Stay on top of real-time developer discussions on daily.dev. Join conversations happening now and engage with the most active community members.',
logo: `${baseUrl}/favicon-32x32.png`,
icon: `${baseUrl}/favicon-32x32.png`,
language: 'en-us',
};
}
25 changes: 14 additions & 11 deletions lib/routes/daily/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '@/types';
import { getData, getList, getRedirectedLink } from './utils.js';
import { baseUrl, getData, getList } from './utils.js';

const variables = {
version: 11,
Expand Down Expand Up @@ -28,6 +28,7 @@ const query = `
edges {
node {
...FeedPost
contentHtml
}
}
}
Expand All @@ -42,6 +43,7 @@ const query = `
image
readTime
permalink
commentsPermalink
summary
createdAt
numUpvotes
Expand Down Expand Up @@ -72,27 +74,28 @@ export const route: Route = {
example: '/daily',
radar: [
{
source: ['daily.dev/popular'],
source: ['app.daily.dev/popular'],
},
],
name: 'Popular',
maintainers: ['Rjnishant530'],
handler,
url: 'daily.dev/popular',
url: 'app.daily.dev/popular',
};

async function handler() {
const baseUrl = 'https://app.daily.dev/popular';
const link = `${baseUrl}/popular`;

const data = await getData(graphqlQuery);
const list = getList(data);
const items = await getRedirectedLink(list);
const items = getList(data);

return {
title: 'Popular',
link: baseUrl,
title: 'Popular posts on daily.dev',
link,
item: items,
description: 'Popular Posts on Daily.dev',
logo: 'https://app.daily.dev/favicon-32x32.png',
icon: 'https://app.daily.dev/favicon-32x32.png',
description: 'daily.dev is the easiest way to stay updated on the latest programming news. Get the best content from the top tech publications on any topic you want.',
logo: `${baseUrl}/favicon-32x32.png`,
icon: `${baseUrl}/favicon-32x32.png`,
language: 'en-us',
};
}
2 changes: 1 addition & 1 deletion lib/routes/daily/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Daily.dev',
url: 'daily.dev',
url: 'app.daily.dev',
categories: ['social-media'],
lang: 'en',
};
186 changes: 186 additions & 0 deletions lib/routes/daily/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { Route } from '@/types';
import { baseUrl, getBuildId, getData, getList } from './utils';
import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
import { config } from '@/config';

interface Source {
id: string;
name: string;
handle: string;
image: string;
permalink: string;
description: string;
type: string;
}

const sourceFeedQuery = `
query SourceFeed($source: ID!, $loggedIn: Boolean! = false, $first: Int, $after: String, $ranking: Ranking, $supportedTypes: [String!]) {
page: sourceFeed(
source: $source
first: $first
after: $after
ranking: $ranking
supportedTypes: $supportedTypes
) {
...FeedPostConnection
}
}
fragment FeedPostConnection on PostConnection {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
...FeedPost
pinnedAt
contentHtml
...UserPost @include(if: $loggedIn)
}
}
}
fragment FeedPost on Post {
...FeedPostInfo
sharedPost {
id
title
image
readTime
permalink
commentsPermalink
createdAt
type
tags
source {
id
handle
permalink
image
}
slug
}
trending
feedMeta
collectionSources {
handle
image
}
numCollectionSources
updatedAt
slug
}
fragment FeedPostInfo on Post {
id
title
image
readTime
permalink
commentsPermalink
createdAt
commented
bookmarked
views
numUpvotes
numComments
summary
bookmark {
remindAt
}
author {
id
name
image
username
permalink
}
type
tags
source {
id
handle
name
permalink
image
type
}
userState {
vote
flags {
feedbackDismiss
}
}
slug
}
fragment UserPost on Post {
read
upvoted
commented
bookmarked
downvoted
}`;

export const route: Route = {
path: '/source/:sourceId',
example: '/daily/source/hn',
parameters: {
sourceId: 'The source id',
},
radar: [
{
source: ['app.daily.dev/sources/:sourceId'],
},
],
name: 'Source Posts',
maintainers: ['TonyRL'],
handler,
url: 'app.daily.dev',
};

async function handler(ctx) {
const sourceId = ctx.req.param('sourceId');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10;
const link = `${baseUrl}/sources/${sourceId}`;

const buildId = await getBuildId();

const userData = (await cache.tryGet(`daily:source:${sourceId}`, async () => {
const response = await ofetch(`${baseUrl}/_next/data/${buildId}/en/sources/${sourceId}.json`);
return response.pageProps.source;
})) as Source;

const items = await cache.tryGet(
`daily:source:${sourceId}:posts`,
async () => {
const edges = await getData({
query: sourceFeedQuery,
variables: {
source: sourceId,
supportedTypes: ['article', 'video:youtube', 'collection'],
period: 30,
first: limit,
after: '',
loggedIn: false,
},
});
return getList(edges);
},
config.cache.routeExpire,
false
);

return {
title: `${userData.name} posts on daily.dev`,
description: userData.description,
link,
item: items,
image: userData.image,
logo: userData.image,
icon: userData.image,
language: 'en-us',
};
}
Loading

0 comments on commit d676831

Please sign in to comment.