Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Last active March 12, 2018 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastianallgeier/452084d6a3fbd013ec73b71fc470e87c to your computer and use it in GitHub Desktop.
Save bastianallgeier/452084d6a3fbd013ec73b71fc470e87c to your computer and use it in GitHub Desktop.
title: Some title
date: 2018-03-12
Text: Lorem ipsum …
<?php
require 'kirby/bootstrap.php';
// get the current list of blog articles
$articles = page('blog')->children();
// scan a directory with yaml files for each post
$files = Dir::read(__DIR__ . '/articles');
foreach ($files as $filename) {
// read each yaml file
$yaml = Data::read(__DIR__ . '/articles/' . $filename);
$slug = Str::slug($yaml['title']);
$template = 'article';
$articles->create($slug, $template, [
'title' => $yaml['title'],
'date' => $yaml['date'],
'text' => $yaml['text']
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment