-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add back matters (#15687)
- Loading branch information
Showing
9 changed files
with
259 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { baseUrl, gqlEndpoint, parseItem } from './utils'; | ||
|
||
const handler = async (ctx) => { | ||
const { uid } = ctx.req.param(); | ||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; | ||
const response = await ofetch(gqlEndpoint, { | ||
method: 'POST', | ||
body: { | ||
query: `{ | ||
user(input: {userName: "${uid}"}) { | ||
displayName | ||
avatar | ||
info { | ||
description | ||
} | ||
articles(input: {first: ${limit}}) { | ||
edges { | ||
node { | ||
shortHash | ||
title | ||
content | ||
createdAt | ||
author { | ||
displayName | ||
} | ||
tags { | ||
content | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`, | ||
}, | ||
}); | ||
|
||
const user = response.data.user; | ||
|
||
return { | ||
title: `Matters | ${user.displayName}`, | ||
link: `${baseUrl}/@${uid}`, | ||
description: user.info.description, | ||
image: user.avatar, | ||
item: user.articles.edges.map(({ node }) => parseItem(node)), | ||
}; | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/author/:uid', | ||
name: 'Author', | ||
example: '/matters/author/robertu', | ||
parameters: { uid: "Author id, can be found at author's homepage url" }, | ||
maintainers: ['Cerebrater', 'xosdy'], | ||
handler, | ||
radar: [ | ||
{ | ||
source: ['matters.town/:uid'], | ||
target: (params) => `/matters/author/${params.uid.slice(1)}`, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { baseUrl, gqlEndpoint, parseItem } from './utils'; | ||
|
||
const handler = async (ctx) => { | ||
const { type = 'latest' } = ctx.req.param(); | ||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; | ||
const options = { | ||
latest: { | ||
title: '最新', | ||
apiType: 'newest', | ||
}, | ||
heat: { | ||
title: '熱議', | ||
apiType: 'hottest', | ||
}, | ||
essence: { | ||
title: '精華', | ||
apiType: 'icymi', | ||
}, | ||
}; | ||
|
||
const response = await ofetch(gqlEndpoint, { | ||
method: 'POST', | ||
body: { | ||
query: `{ | ||
viewer { | ||
recommendation { | ||
feed: ${options[type].apiType}(input: {first: ${limit}}) { | ||
edges { | ||
node { | ||
shortHash | ||
title | ||
content | ||
createdAt | ||
author { | ||
displayName | ||
} | ||
tags { | ||
content | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`, | ||
}, | ||
}); | ||
|
||
const item = response.data.viewer.recommendation.feed.edges.map(({ node }) => parseItem(node)); | ||
|
||
return { | ||
title: `Matters | ${options[type].title}`, | ||
link: baseUrl, | ||
item, | ||
}; | ||
}; | ||
export const route: Route = { | ||
path: '/latest/:type?', | ||
name: 'Latest, heat, essence', | ||
example: '/matters/latest/heat', | ||
parameters: { uid: 'Defaults to latest, see table below' }, | ||
maintainers: ['xyqfer', 'Cerebrater', 'xosdy'], | ||
handler, | ||
radar: [ | ||
{ | ||
source: ['matters.town'], | ||
}, | ||
], | ||
description: `| 最新 | 热门 | 精华 | | ||
| ------ | ---- | ------- | | ||
| latest | heat | essence |`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'Matters', | ||
url: 'matters.town', | ||
categories: ['new-media'], | ||
}; |
Oops, something went wrong.