Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create domain filters for patterns without filters #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrmod
Copy link
Member

@chrmod chrmod commented Apr 20, 2023

Those patterns come from whotracks.me tracker database which had domain association only. For those patterns that had no filter, we create domain filters based on the domains that were already assigned to the pattern.

To prevent breakage all domain filters are scoped to third-parties only.

@chrmod
Copy link
Member Author

chrmod commented Apr 20, 2023

script used to update the files

import { readFileSync, writeFileSync } from 'fs';
import { getSpecs } from './scripts/helpers.js';

const template = (spec, filters) => `${spec}
---filters
${filters.map((filter) => `${filter}`).join('\n')}
---filters
`;

const specs = getSpecs('patterns').filter(([id, spec]) => {
  if (!spec.field('filters').optionalStringValue()) {
    return true;
  }
});

specs.forEach(([id, spec]) => {
  const filters = [];
  const domains = spec.field('domains').optionalStringValue();
  if (domains) {
    for (const line of domains.split(/[\r\n]+/g)) {
      const trimmed = line.trim();
      filters.push(`||${trimmed}^$3p`);
    }

    const filename = `./db/patterns/${id}.eno`;
    const rawSpec = readFileSync(filename, { encoding: 'utf-8' });
    writeFileSync(filename, template(rawSpec, filters));
  }
});

@chrmod chrmod marked this pull request as draft July 19, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant