Skip to content

Commit

Permalink
all: imp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Oct 21, 2022
1 parent b7f961c commit 8341c13
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Filters/DnsBlocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getObjDiff,
} from '../../helpers/helpers';

const filtersCatalog = require('../../helpers/filters/filters.json');
import filtersCatalog from '../../helpers/filters/filters';

class DnsBlocklist extends Component {
componentDidMount() {
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/Filters/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import classNames from 'classnames';
import { validatePath, validateRequiredValue } from '../../helpers/validators';
import { CheckboxField, renderInputField } from '../../helpers/form';
import { MODAL_OPEN_TIMEOUT, MODAL_TYPE, FORM_NAME } from '../../helpers/constants';

const filtersCatalog = require('../../helpers/filters/filters.json');
import filtersCatalog from '../../helpers/filters/filters';

const getIconsData = (homepage, source) => ([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
// Code generated by go run ./scripts/vetted-filters/main.go; DO NOT EDIT.

/* eslint quote-props: 'off', quotes: 'off', comma-dangle: 'off', semi: 'off' */

export default {
"categories": {
"general": {
"name": "filter_category_general",
Expand Down
24 changes: 19 additions & 5 deletions scripts/vetted-filters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -77,15 +78,28 @@ func main() {
}
}

b, err := json.MarshalIndent(aghFlt, "", " ")
check(err)
buf := &bytes.Buffer{}
_, _ = buf.WriteString(jsHeader)

enc := json.NewEncoder(buf)
enc.SetIndent("", " ")

b = append(b, '\n')
err = enc.Encode(aghFlt)
check(err)

err = maybe.WriteFile("client/src/helpers/filters/filters.json", b, 0o644)
err = maybe.WriteFile("client/src/helpers/filters/filters.js", buf.Bytes(), 0o644)
check(err)
}

// jsHeader is the header for the generates JavaScript file. It informs the
// reader that the file is generated and disables some style-related eslint
// checks.
const jsHeader = `// Code generated by go run ./scripts/vetted-filters/main.go; DO NOT EDIT.
/* eslint quote-props: 'off', quotes: 'off', comma-dangle: 'off', semi: 'off' */
export default `

// check is a simple error-checking helper for scripts.
func check(err error) {
if err != nil {
Expand Down Expand Up @@ -127,7 +141,7 @@ func (f *hlFiltersFilter) category() (cat string) {
}

// aghFilters is the JSON structure for AdGuard Home's list of vetted filtering
// rule list in file client/src/helpers/filters/filters.json.
// rule list in file client/src/helpers/filters/filters.js.
type aghFilters struct {
Categories map[string]*aghFiltersCategory `json:"categories"`
Filters map[string]*aghFiltersFilter `json:"filters"`
Expand Down

0 comments on commit 8341c13

Please sign in to comment.