node-website-scraper icon indicating copy to clipboard operation
node-website-scraper copied to clipboard

How do I change the style file name?

Open enotmen opened this issue 3 years ago • 1 comments

👋

How do I change the style file name?

On website:

<link rel="stylesheet" href="/css.php?css=public%3Anormalize.css%2Cpublic%3Acore.less%2Cpublic%3Aapp.less&amp;s=4&amp;l=2&amp;d=1662797562&amp;k=ff35318db5867bf126885c00dd9035e798564192" />

After parse:

<link rel="stylesheet" href="css_css%3Dpublic%253Anormalize.css%252Cpublic%253Acore.less%252Cpublic%253Aapp.less%26s%3D4%26l%3D2%26d%3D1662797562%26k%3Dff35318db5867bf126885c00dd9035e798564192.php">

this file is not loaded and there are no styles on the site.

enotmen avatar Sep 10 '22 09:09 enotmen

Hi @enotmen 👋

Are you using bySiteStructure filenameGenerator? It intentionally keeps query string params as part of the filename. If yes - then I suggest trying default filenameGenerator byType or create custom plugin with generateFilename action

s0ph1e avatar Sep 11 '22 19:09 s0ph1e

import bySiteStructureFilenameGenerator from "./node_modules/website-scraper/lib/filename-generator/by-site-structure.js";

class MyPlugin {
  apply(registerAction) {
    let defaultFilename;

    registerAction("beforeStart", ({ options }) => {
      defaultFilename = options.defaultFilename;
    });
    registerAction("generateFilename", ({ resource }) => {
      const filename = bySiteStructureFilenameGenerator(resource, {
        defaultFilename,
      });
      if (filename.indexOf("ff35318db5867bf126885c00dd9035e798564192") + 1) {
        filename = "web.com/styles/style.css";
      }
      return { filename };
    });
  }
}

Thx.

enotmen avatar Sep 26 '22 02:09 enotmen