You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/terms/explanation/filters.md
+7-11Lines changed: 7 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,9 @@ Filters are necessary when standard CSS selectors and range selectors cannot ade
13
13
14
14
Use filters when:
15
15
16
-
-**CSS selectors are insufficient**: When noise appears within content that can't be targeted with selectors or [range selectors]({{< relref "terms/explanation/range-selectors" >}}) with the [`select`]({{< relref "terms/reference/declaration/#ref-select" >}}) and [`remove`]({{< relref "terms/reference/declaration/#ref-remove" >}}) properties.
17
-
-**Content is dynamically generated**: When elements change on each page load, such as:
18
-
- Tracking parameters in URLs (e.g., `utm_source`, `utm_medium`)
19
-
- Dynamic elements with changing classes or IDs
20
-
-**Complex tasks are needed**: When content transformation is needed such as:
21
-
- Converting images to base64 to store them in the terms version.
22
-
- Converting date-based content to a more stable format (e.g., "Updated X days ago" to "Last updated on YYYY-MM-DD")
16
+
-**CSS selectors are insufficient**, for example when noise appears within content that can't be targeted with selectors or [range selectors]({{< relref "terms/explanation/range-selectors" >}}) with the [`select`]({{< relref "terms/reference/declaration/#ref-select" >}}) and [`remove`]({{< relref "terms/reference/declaration/#ref-remove" >}}) properties.
17
+
-**Content is dynamically generated**, for example when elements change on each page load with tracking parameters in URLs (like `utm_source`, `utm_medium`) or dynamic elements with changing classes or IDs.
18
+
-**Complex tasks are needed**, for example when content transformation is required such as converting images to base64 to store them in the terms version or converting date-based content to a more stable format (like "Updated X days ago" to "Last updated on YYYY-MM-DD").
23
19
24
20
## How filters work
25
21
@@ -29,16 +25,16 @@ Filters are JavaScript functions that receive a JSDOM document instance and can
29
25
30
26
When designing filters, follow these core principles:
31
27
32
-
-**Be specific**: Target only the noise you want to remove. Avoid broad selectors that might accidentally remove important content.
28
+
-**Be specific**: target only the noise you want to remove. Avoid broad selectors that might accidentally remove important content.
33
29
34
30
> For example, if your filter converts relative dates to absolute dates, use `.metadata time` not `time` which might also affect important effective dates within the terms content.
35
31
36
-
-**Be idempotent**: Filters should produce the same result even if run multiple times on their own output. This ensures consistency and prevents unexpected behavior.
32
+
-**Be idempotent**: filters should produce the same result even if run multiple times on their own output. This ensures consistency and prevents unexpected behavior.
37
33
38
34
> For example, if your filter adds section numbers like "1." to headings, check if numbers already exist to prevent "1. Privacy Policy" from becoming "1. 1. Privacy Policy" on repeated runs.
39
35
40
-
-**Be efficient**: Use efficient DOM queries and avoid unnecessary operations. Process only the elements you need to modify.
36
+
-**Be efficient**: use efficient DOM queries and avoid unnecessary operations. Process only the elements you need to modify.
41
37
42
38
> For example, if your filter updates timestamp elements with a specific class, use `document.querySelector('.timestamp')` instead of `document.querySelectorAll('*')` followed by filtering for timestamp elements.
43
39
44
-
-**Be safe**: Filters should not accidentally remove important content. The generated version should always be checked after adding a filter to ensure it still contains the whole terms content.
40
+
-**Be safe**: filters should not accidentally remove important content. The generated version should always be checked after adding a filter to ensure it still contains the whole terms content.
0 commit comments