Skip to content

Commit

Permalink
fix: respond with markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nomagick committed Apr 25, 2024
1 parent 69231ad commit a6a5b7c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions backend/functions/src/cloud-functions/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class CrawlerHost extends RPCHost {
return turnDownService;
}

async formatSnapshot(mode: string | 'markdown' | 'full-markdown' | 'html' | 'text' | 'screenshot', snapshot: PageSnapshot & {
async formatSnapshot(mode: string | 'markdown' | 'html' | 'text' | 'screenshot', snapshot: PageSnapshot & {
screenshotUrl?: string;
}, nominalUrl?: URL) {
if (mode === 'screenshot') {
Expand Down Expand Up @@ -112,8 +112,8 @@ export class CrawlerHost extends RPCHost {
};
}

const toBeTurnedToMd = mode === 'full-markdown' ? snapshot.html : snapshot.parsed?.content;
let turnDownService = mode === 'markdown' ? this.getTurndown('without any rule') : this.getTurndown();
const toBeTurnedToMd = mode === 'markdown' ? snapshot.html : snapshot.parsed?.content;
let turnDownService = mode === 'markdown' ? this.getTurndown() : this.getTurndown('without any rule');
for (const plugin of this.turnDownPlugins) {
turnDownService = turnDownService.use(plugin);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ export class CrawlerHost extends RPCHost {
mixins.push(`Published Time: ${this.publishedTime}`);
}

if (mode === 'full-markdown') {
if (mode === 'markdown') {
return this.content;
}

Expand Down Expand Up @@ -253,14 +253,12 @@ ${this.content}
schema: { type: 'string' }
},
'X-Respond-With': {
description: `Specifies the form factor of the crawled data you prefer. \n\n` +
description: `Specifies the (non-default) form factor of the crawled data you prefer. \n\n` +
`Supported formats:\n` +
`- markdown\n` +
`- full-markdown\n` +
`- html\n` +
`- text\n` +
`- screenshot\n\n` +
`Defaults to: markdown`
`- screenshot\n`
,
in: 'header',
schema: { type: 'string' }
Expand Down Expand Up @@ -322,7 +320,7 @@ ${this.content}
});
}

const customMode = ctx.req.get('x-respond-with') || 'markdown';
const customMode = ctx.req.get('x-respond-with') || 'default';
const noCache = Boolean(ctx.req.get('x-no-cache'));
const cookies: CookieParam[] = [];
const setCookieHeaders = ctx.req.headers['x-set-cookie'];
Expand Down

0 comments on commit a6a5b7c

Please sign in to comment.