-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
35 lines (25 loc) · 785 Bytes
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
// Config
$pattern = '/(?P<prefix><dc:subject>)(?P<subject>[^<]+)/u';
$buildDir = __DIR__ . '/.build/';
$feeds = [
['https://feeds.pinboard.in/rss/popular/', 'popular.xml']
];
// Functions
$rewrite = function (string $source) use ($pattern) {
return preg_replace_callback($pattern, function (array $matches) {
$newSubject = implode(', ', explode(' ', $matches['subject']));
return $matches['prefix'] . $newSubject;
}, file_get_contents($source));
};
$save = function (string $contents, string $name) use ($buildDir) {
file_put_contents($buildDir . $name, $contents);
};
// Execution
if (!file_exists($buildDir)) {
mkdir($buildDir);
}
foreach ($feeds as $feed) {
[$url, $filename] = $feed;
$save($rewrite($url), $filename);
}