mirror of
https://github.com/wassname/talk.git
synced 2026-08-04 13:23:35 +08:00
[CORL-735] Scraper support for JSON Linked Data (#2671)
* feat: add support for application/json+ld parsing - upgraded scraper packages to use new jsonld parser - waiting on https://github.com/microlinkhq/metascraper/pull/225 for merging - fixes #2670 * chore: metascraper upgrades
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import { Rule, Ruler } from "metascraper";
|
||||
|
||||
export const wrap = (rule: Rule): Ruler => ({ htmlDom, url }) =>
|
||||
rule(htmlDom, url);
|
||||
@@ -1,8 +1,12 @@
|
||||
import { $jsonld } from "@metascraper/helpers";
|
||||
import { Rules } from "metascraper";
|
||||
|
||||
import { wrap } from "./helpers";
|
||||
|
||||
export const modifiedScraper = (): Rules => ({
|
||||
modified: [
|
||||
// From: http://ogp.me/#type_article
|
||||
({ htmlDom: $ }) => $('meta[property="article:modified"]').attr("content"),
|
||||
wrap($jsonld("dateModified")),
|
||||
wrap($ => $('meta[property="article:modified"]').attr("content")),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { $jsonld } from "@metascraper/helpers";
|
||||
import { Rules } from "metascraper";
|
||||
|
||||
import { wrap } from "./helpers";
|
||||
|
||||
export const sectionScraper = (): Rules => ({
|
||||
section: [
|
||||
// From: http://ogp.me/#type_article
|
||||
({ htmlDom: $ }) => $('meta[property="article:section"]').attr("content"),
|
||||
wrap($jsonld("articleSection")),
|
||||
wrap($ => $('meta[property="article:section"]').attr("content")),
|
||||
],
|
||||
});
|
||||
|
||||
Vendored
+18
-10
@@ -1,17 +1,21 @@
|
||||
declare module "metascraper" {
|
||||
export interface Scraper {
|
||||
(
|
||||
options: {
|
||||
url: string;
|
||||
html: string;
|
||||
}
|
||||
): Promise<Record<string, string | undefined>>;
|
||||
(options: { url: string; html: string }): Promise<
|
||||
Record<string, string | undefined>
|
||||
>;
|
||||
}
|
||||
|
||||
export type Rules = Record<
|
||||
string,
|
||||
Array<(options: { htmlDom: CheerioSelector }) => string | undefined>
|
||||
>;
|
||||
export type Ruler = (options: {
|
||||
htmlDom: CheerioSelector;
|
||||
url: string;
|
||||
}) => string | undefined;
|
||||
|
||||
export type Rule = (
|
||||
htmlDom: CheerioSelector,
|
||||
url: string
|
||||
) => string | undefined;
|
||||
|
||||
export type Rules = Record<string, Array<Ruler>>;
|
||||
|
||||
export function load(rules: Rules[]): Scraper;
|
||||
}
|
||||
@@ -40,3 +44,7 @@ declare module "metascraper-title" {
|
||||
import { Rules } from "metascraper";
|
||||
export default function def(): Rules;
|
||||
}
|
||||
|
||||
declare module "@metascraper/helpers" {
|
||||
export const $jsonld: any;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user