-
Notifications
You must be signed in to change notification settings - Fork 9.8k
feat(route/transform): add date format to params #21929
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { config } from '@/config'; | |
| import ConfigNotFoundError from '@/errors/types/config-not-found'; | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| function jsonGet(obj, attr) { | ||
| if (typeof attr !== 'string') { | ||
|
|
@@ -49,6 +50,8 @@ export const route: Route = { | |
| | \`itemLinkPrefix\` | Optional Prefix for \`itemLink\` value | \`string\` | None | | ||
| | \`itemDesc\` | The JSON Path as \`description\` in \`item\` | \`string\` | None | | ||
| | \`itemPubDate\` | The JSON Path as \`pubDate\` in \`item\` | \`string\` | None | | ||
| | \`itemPubDateFmt\` | Date format string for \`day.js\` | \`string\` | None | | ||
|
|
||
|
|
||
| ::: tip | ||
| JSON Path only supports format like \`a.b.c\`. if you need to access arrays, like \`a[0].b\`, you can write it as \`a.0.b\`. | ||
|
|
@@ -103,11 +106,15 @@ async function handler(ctx) { | |
| if (link && !link.startsWith('http')) { | ||
| link = `${new URL(url).origin}${link}`; | ||
| } | ||
|
|
||
| const pubDateRaw = routeParams.get('itemPubDate') ? jsonGet(item, routeParams.get('itemPubDate')) : ''; | ||
| const pubDate = routeParams.get('itemPubDateFmt') ? parseDate(pubDateRaw, routeParams.get('itemPubDateFmt')) : pubDateRaw; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also check if
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I implemented it with a simple logic or |
||
|
|
||
| return { | ||
| title: jsonGet(item, routeParams.get('itemTitle')), | ||
| link, | ||
| description: routeParams.get('itemDesc') ? jsonGet(item, routeParams.get('itemDesc')) : '', | ||
| pubDate: routeParams.get('itemPubDate') ? jsonGet(item, routeParams.get('itemPubDate')) : '', | ||
| pubDate, | ||
| }; | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.