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

fix(daily dev): fixed routes and added one new one #18021

Merged
merged 8 commits into from
Jan 5, 2025
Merged
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
6 changes: 4 additions & 2 deletions lib/routes/alistapart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { getData, getList } from './utils';

export const route: Route = {
path: '/',
categories: ['programming'],
radar: [
{
source: ['alistapart.com/articles/'],
target: '',
target: '/',
},
],
name: 'Unknown',
name: 'Home Feed',
maintainers: ['Rjnishant530'],
handler,
url: 'alistapart.com/articles/',
example: '/alistapart',
};

async function handler() {
Expand Down
1 change: 1 addition & 0 deletions lib/routes/alistapart/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const route: Route = {
radar: [
{
source: ['alistapart.com/blog/topic/:topic'],
target: '/:topic',
},
],
name: 'Topics',
Expand Down
46 changes: 40 additions & 6 deletions lib/routes/daily/discussed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '@/types';
import { baseUrl, getData, getList } from './utils.js';
import { Route, ViewType } from '@/types';
import { baseUrl, getData, getList, variables } from './utils.js';

const query = `
query MostDiscussedFeed(
Expand Down Expand Up @@ -52,8 +52,9 @@ const query = `
`;

export const route: Route = {
path: '/discussed',
example: '/daily/discussed',
path: '/discussed/:period?/:innerSharedContent?/:dateSort?',
example: '/daily/discussed/30',
view: ViewType.Articles,
radar: [
{
source: ['app.daily.dev/discussed'],
Expand All @@ -63,19 +64,52 @@ export const route: Route = {
maintainers: ['Rjnishant530'],
handler,
url: 'app.daily.dev/discussed',
parameters: {
innerSharedContent: {
description: 'Where to Fetch inner Shared Posts instead of original',
default: 'false',
options: [
{ value: 'false', label: 'False' },
{ value: 'true', label: 'True' },
],
},
dateSort: {
description: 'Sort posts by publication date instead of popularity',
default: 'true',
options: [
{ value: 'false', label: 'False' },
{ value: 'true', label: 'True' },
],
},
period: {
description: 'Period of Lookup',
default: '7',
options: [
{ value: '7', label: 'Last Week' },
{ value: '30', label: 'Last Month' },
{ value: '365', label: 'Last Year' },
],
},
},
};

async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20;
const link = `${baseUrl}/discussed`;
const innerSharedContent = ctx.req.param('innerSharedContent') ? JSON.parse(ctx.req.param('innerSharedContent')) : false;
const dateSort = ctx.req.param('dateSort') ? JSON.parse(ctx.req.param('dateSort')) : true;
const period = ctx.req.param('period') ? Number.parseInt(ctx.req.param('period'), 10) : 7;

const link = `${baseUrl}/posts/discussed`;

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

return {
title: 'Real-time discussions in the developer community | daily.dev',
Expand Down
101 changes: 0 additions & 101 deletions lib/routes/daily/index.ts

This file was deleted.

182 changes: 182 additions & 0 deletions lib/routes/daily/popular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { Route, ViewType } from '@/types';
import { baseUrl, getData, getList, variables } from './utils.js';

const query = `
query AnonymousFeed(
$loggedIn: Boolean! = false
$first: Int
$after: String
$ranking: Ranking
$version: Int
$supportedTypes: [String!] = ["article","share","freeform","video:youtube","collection"]
) {
page: anonymousFeed(
first: $first
after: $after
ranking: $ranking
version: $version
supportedTypes: $supportedTypes
) {
...FeedPostConnection
}
}

fragment FeedPostConnection on PostConnection {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
...FeedPost
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
clickbaitTitleDetected
}
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
clickbaitTitleDetected
}

fragment UserPost on Post {
read
upvoted
commented
bookmarked
downvoted
}
`;

export const route: Route = {
path: '/popular/:innerSharedContent?/:dateSort?',
example: '/daily/popular',
view: ViewType.Articles,
radar: [
{
source: ['app.daily.dev/popular'],
},
],
parameters: {
innerSharedContent: {
description: 'Where to Fetch inner Shared Posts instead of original',
default: 'false',
options: [
{ value: 'false', label: 'False' },
{ value: 'true', label: 'True' },
],
},
dateSort: {
description: 'Sort posts by publication date instead of popularity',
default: 'true',
options: [
{ value: 'false', label: 'False' },
{ value: 'true', label: 'True' },
],
},
},
name: 'Popular',
maintainers: ['Rjnishant530'],
handler,
url: 'app.daily.dev/popular',
};

async function handler(ctx) {
const link = `${baseUrl}/posts`;
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15;
const innerSharedContent = ctx.req.param('innerSharedContent') ? JSON.parse(ctx.req.param('innerSharedContent')) : false;
const dateSort = ctx.req.param('dateSort') ? JSON.parse(ctx.req.param('dateSort')) : true;

const data = await getData({
query,
variables: {
...variables,
ranking: 'POPULARITY',
first: limit,
},
});
const items = getList(data, innerSharedContent, dateSort);

return {
title: 'Popular posts on daily.dev',
link,
item: items,
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',
};
}
Loading
Loading