feat(rss-feed): add configurable description max length (#7051)
Co-authored-by: ajnart <thomas@ajnart.dev>
This commit is contained in:
1 parent
a7fac57d62
commit
68238fa69b
6 files changed
+21
-1
No files matched your search
@@ -42,6 +42,12 @@ export const rssFeedWidget: WidgetDefinition = {
|
|||||||
values: "1-50",
|
values: "1-50",
|
||||||
defaultValue: "5",
|
defaultValue: "5",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Description max length",
|
||||||
|
description: "Maximum number of characters to keep from the feed description",
|
||||||
|
values: "1-5000",
|
||||||
|
defaultValue: "250",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Amount posts limit",
|
name: "Amount posts limit",
|
||||||
description: "Maximum number of posts to show",
|
description: "Maximum number of posts to show",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ const redactFeedFailureMessage = (message: string) => message.replace(/https?:\/
|
|||||||
const feedsInput = z.object({
|
const feedsInput = z.object({
|
||||||
urls: z.array(z.string()).max(100),
|
urls: z.array(z.string()).max(100),
|
||||||
maximumAmountPosts: z.number(),
|
maximumAmountPosts: z.number(),
|
||||||
|
descriptionMaxLength: z.number().int().min(1).max(5000).default(250),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const rssFeedRouter = createTRPCRouter({
|
export const rssFeedRouter = createTRPCRouter({
|
||||||
@@ -43,6 +44,7 @@ export const rssFeedRouter = createTRPCRouter({
|
|||||||
const innerHandler = rssFeedsRequestHandler.handler({
|
const innerHandler = rssFeedsRequestHandler.handler({
|
||||||
url,
|
url,
|
||||||
count: input.maximumAmountPosts,
|
count: input.maximumAmountPosts,
|
||||||
|
descriptionMaxLength: input.descriptionMaxLength,
|
||||||
});
|
});
|
||||||
return await innerHandler.getDataAsync();
|
return await innerHandler.getDataAsync();
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ const logger = createLogger({ module: "rssFeedsRequestHandler" });
|
|||||||
|
|
||||||
export const rssFeedsRequestHandler = createWidgetRequestHandler({
|
export const rssFeedsRequestHandler = createWidgetRequestHandler({
|
||||||
// Authorized editors can supply arbitrary URLs, so keep this cache process-local and bounded.
|
// Authorized editors can supply arbitrary URLs, so keep this cache process-local and bounded.
|
||||||
async requestAsync(input: { url: string; count: number }, signal) {
|
async requestAsync(input: { url: string; count: number; descriptionMaxLength: number }, signal) {
|
||||||
const result = (await extract(
|
const result = (await extract(
|
||||||
input.url,
|
input.url,
|
||||||
{
|
{
|
||||||
|
descriptionMaxLen: input.descriptionMaxLength,
|
||||||
getExtraEntryFields: (feedEntry) => {
|
getExtraEntryFields: (feedEntry) => {
|
||||||
const media = attemptGetImageFromEntry(input.url, feedEntry);
|
const media = attemptGetImageFromEntry(input.url, feedEntry);
|
||||||
if (!media) {
|
if (!media) {
|
||||||
|
|||||||
@@ -4480,6 +4480,10 @@
|
|||||||
"textLinesClamp": {
|
"textLinesClamp": {
|
||||||
"label": "Description line clamp"
|
"label": "Description line clamp"
|
||||||
},
|
},
|
||||||
|
"descriptionMaxLength": {
|
||||||
|
"label": "Description max length",
|
||||||
|
"description": "Maximum number of characters to keep from the feed description"
|
||||||
|
},
|
||||||
"maximumAmountPosts": {
|
"maximumAmountPosts": {
|
||||||
"label": "Amount posts limit"
|
"label": "Amount posts limit"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ export default function RssFeed({ options, width, height, displayMode }: WidgetC
|
|||||||
const feed = useLiveFeed({
|
const feed = useLiveFeed({
|
||||||
urls: options.feedUrls,
|
urls: options.feedUrls,
|
||||||
maximumAmountPosts: typeof options.maximumAmountPosts === "number" ? options.maximumAmountPosts : 100,
|
maximumAmountPosts: typeof options.maximumAmountPosts === "number" ? options.maximumAmountPosts : 100,
|
||||||
|
descriptionMaxLength:
|
||||||
|
typeof options.descriptionMaxLength === "number" ? options.descriptionMaxLength : 250,
|
||||||
});
|
});
|
||||||
|
|
||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const { definition, componentLoader } = createWidgetDefinition("rssFeed",
|
|||||||
widgetQueryInputMatches(input, {
|
widgetQueryInputMatches(input, {
|
||||||
urls: scope.options.feedUrls,
|
urls: scope.options.feedUrls,
|
||||||
maximumAmountPosts: scope.options.maximumAmountPosts,
|
maximumAmountPosts: scope.options.maximumAmountPosts,
|
||||||
|
descriptionMaxLength: scope.options.descriptionMaxLength,
|
||||||
}),
|
}),
|
||||||
refetchInterval: null,
|
refetchInterval: null,
|
||||||
errors: {
|
errors: {
|
||||||
@@ -39,6 +40,10 @@ export const { definition, componentLoader } = createWidgetDefinition("rssFeed",
|
|||||||
defaultValue: 5,
|
defaultValue: 5,
|
||||||
validate: z.number().min(1).max(50),
|
validate: z.number().min(1).max(50),
|
||||||
}),
|
}),
|
||||||
|
descriptionMaxLength: factory.number({
|
||||||
|
defaultValue: 250,
|
||||||
|
validate: z.number().int().min(1).max(5000),
|
||||||
|
}),
|
||||||
maximumAmountPosts: factory.number({
|
maximumAmountPosts: factory.number({
|
||||||
defaultValue: 100,
|
defaultValue: 100,
|
||||||
validate: z.number().min(1).max(9999),
|
validate: z.number().min(1).max(9999),
|
||||||
|
|||||||
Reference in new issue
Block a user