Here’s the config:
<?php
return [
'debug' => false,
'languages' => true,
'fatal' => function() {
include kirby()->root('templates') . '/fatal.php' ;
},
'content' => [
'extension' => 'md'
],
'markdown' => [
'extra' => true
],
'routes' => [
// Feeds
[
'pattern' => ['feed/index', 'feed/xml', 'feed/atom'],
'method' => 'GET',
'action' => function () {
$options = [
'title' => 'Master Feed',
'description' => 'All content',
'link' => 'home',
'snippet' => 'feed/atom'
];
return collection("masterfeed")->limit(30)->feed($options);
}
]
// etc.
],
'api' => [
'slug' => 'app'
],
'cache' => [
'pages' => [
'active' => true,
'type' => 'apcu'
]
]
];
The script creating the pages:
<?php
define('DS', DIRECTORY_SEPARATOR);
// bootstrap kirby
require(__DIR__ . DS . '../html' . DS . 'kirby' . DS . 'bootstrap.php');
$kirby = new Kirby;
// authenticate as super user
$kirby->impersonate('kirby');
echo 'Loaded instance: ' . $kirby->site()->title() . "\r\n";
$pinboardlinks = function(){
$feeddata = [];
$pinboardurl = 'http://feeds.pinboard.in/json/…';
echo 'Requesting json-data from ' . $pinboardurl . "\r\n";
$request = remote::request($pinboardurl);
if (!empty($request->content)) {
$feeddata = json_decode($request->content, true);
} else {
echo 'Could not get data from the pinboard feed.';
die();
}
return array_reverse($feeddata);
};
foreach($pinboardlinks() as $linkentry){
$data = [
'timestamp' => $linkentry['dt'],
'link' => $linkentry['u'],
'title' => $linkentry['d'],
'text' => $linkentry['n'],
'date' => date("Y-m-d H:i:s", strtotime($linkentry['dt'])),
'imported' => date("Y-m-d H:i:s", time()),
'tags' => implode(", ",$linkentry['t'])
];
if (page('links')->grandChildren()->filterBy('Link', $data['link'])->isEmpty()) {
echo 'Creating new entry: ';
$pageslug = Str::slug(Str::short($data['title'], 60, ''), '-', 'a-z0-9@._-');
echo $pageslug . "\r\n";
try {
$createNewLinkEntry = page('links/en')->createChild([
'slug' => $pageslug,
'template' => 'link',
'draft' => true,
'content' => [
'title' => $data['title'],
'autoid' => '',
'date' => $data['date'],
'imported' => $data['imported'],
'link' => $data['link'],
'tags' => $data['tags'],
'text' => $data['text']
]
])->publish()->changeStatus('listed');
} catch(Exception $e) {
echo 'ERROR: ' . $pageslug . ': ' . $e->getMessage() . "\r\n";
}
} else {
echo 'Entry already exists for ' . $data['link'] . "\r\n";
}
};
echo 'Link entries have been updated' . "\r\n";
?>