How to use the metascraper.RULES function in metascraper

To help you get started, we’ve selected a few metascraper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github olymp / olymp / packages / scrape / server / graphql.es6 View on Github external
}
    return value;
  };
  function wrapDescription(rule) {
    return $ => {
      let value = rule($);
      if (typeof value !== 'string') {
        return undefined;
      }
      value = value.trim();
      value = value.replace(/^[A-Z\s]+\s+[-—–]\s+/, '');
      return trimLength(value, 160);
    };
  }
  return {
    ...Metascraper.RULES,
    url: () => url.href,
    origin: () => url.origin,
    description: [
      ...Metascraper.RULES.description,
      wrapDescription($ =>
        $('p')
          .first()
          .text(),
      ),
    ],
    favicon: () => ({
      url: `https://res.cloudinary.com/demo/image/fetch/${url.origin}/favicon.ico`,
      width: 32,
      height: 32,
    }),
    extract: $ =>
github olymp / olymp / packages / scrape / server / graphql.es6 View on Github external
return $ => {
      let value = rule($);
      if (typeof value !== 'string') {
        return undefined;
      }
      value = value.trim();
      value = value.replace(/^[A-Z\s]+\s+[-—–]\s+/, '');
      return trimLength(value, 160);
    };
  }
  return {
    ...Metascraper.RULES,
    url: () => url.href,
    origin: () => url.origin,
    description: [
      ...Metascraper.RULES.description,
      wrapDescription($ =>
        $('p')
          .first()
          .text(),
      ),
    ],
    favicon: () => ({
      url: `https://res.cloudinary.com/demo/image/fetch/${url.origin}/favicon.ico`,
      width: 32,
      height: 32,
    }),
    extract: $ =>
      $('p')
        .first()
        .text(),
    image: [

metascraper

A library to easily scrape metadata from an article on the web using Open Graph, JSON+LD, regular HTML metadata, and series of fallbacks.

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis