Skip to content

Commit d19bad9

Browse files
committed
Improve filter docs
1 parent be7bb36 commit d19bad9

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

content/terms/reference/declaration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ As an array of those:
146146
"filter": [
147147
"filterName1",
148148
{
149-
"filterName2": "params"
149+
"filterName2": "param"
150150
}
151151
]
152152
```

content/terms/reference/filters.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ Can be used as follows in the declaration:
4949
}
5050
```
5151

52+
Example:
53+
54+
```js
55+
export function convertTimeAgoToDate(document) {
56+
const timeElements = document.querySelectorAll('time');
57+
58+
timeElements.forEach(timeElement => {
59+
const dateTimeValue = timeElement.getAttribute('datetime');
60+
const textNode = document.createTextNode(dateTimeValue);
61+
timeElement.parentNode.replaceChild(textNode, timeElement);
62+
});
63+
}
64+
```
65+
66+
```json
67+
{
68+
"name": "MyService",
69+
"terms": {
70+
"Privacy Policy": {
71+
"fetch": "https://example.com/privacy",
72+
"select": ".content",
73+
"filter": [
74+
"convertTimeAgoToDate"
75+
]
76+
}
77+
}
78+
}
79+
```
80+
81+
Result:
82+
83+
```diff
84+
- <p class="meta-data">Last update: <time datetime="2025-06-23T11:16:36Z" title="06/23/2025, 13:16" data-datetime="relative">2 months ago</time></p>
85+
+ <p class="meta-data">Last update: 2025-06-23T11:16:36Z</p>
86+
```
87+
5288
### Filter with parameters
5389

5490
```js
@@ -77,3 +113,50 @@ Can be used as follows in the declaration:
77113
}
78114
}
79115
```
116+
117+
Example:
118+
119+
```js
120+
export function removeLinksWithText(document, text) {
121+
const links = document.querySelectorAll('a');
122+
links.forEach(link => {
123+
if (link.textContent.trim() === text) {
124+
link.remove();
125+
}
126+
});
127+
}
128+
```
129+
130+
```json
131+
{
132+
"name": "MyService",
133+
"terms": {
134+
"Privacy Policy": {
135+
"fetch": "https://example.com/privacy",
136+
"select": ".content",
137+
"filter": [
138+
{ "removeLinksWithText": "Return to previous section" }
139+
{ "removeLinksWithText": "Go to next section" }
140+
]
141+
}
142+
}
143+
}
144+
```
145+
146+
Result:
147+
148+
```diff
149+
<div id="section1">
150+
- <a href="#section2">Go to next section</a>
151+
<p>...</p>
152+
</div>
153+
<div id="section2">
154+
- <a href="#section1">Return to previous section</a>
155+
- <a href="#section3">Go to next section</a>
156+
<p>...</p>
157+
</div>
158+
<div id="section3">
159+
- <a href="#section2">Return to previous section</a>
160+
<p>...</p>
161+
</div>
162+
```

0 commit comments

Comments
 (0)