chrisullyott/csv-to-grav

Migrate a site to Grav, a flat-file CMS.

dev-master 2018-01-01 20:13 UTC

This package is auto-updated.

Last update: 2024-03-20 17:52:32 UTC


README

Grav uses Markdown files instead of a database to serve content. When migrating your website or blog to Grav, you'll need to convert your existing HTML content to Markdown, and arrange your posts in a directory structure that Grav can understand.

Some specific migration assistants are available to help you do this, but if you just want to convert an arbitrary CSV into Grav posts, this tool can help. In summary, csv-to-grav reads a CSV file and builds a Grav file tree, converting your content to Markdown and your metadata to Yaml.

When finished, you'll only need to move the output directory into your Grav installation and use a Collection to create a list and detail view of your content.

Setup

Install dependencies with Composer.

Run

Modify convert.php ...

$conversion = new CsvToGrav('example.csv');

$conversion->setColumnMap(array(
    'title' => 'example_title_field',
    'date'  => 'example_date_field',
    'html'  => 'example_html_field'
));

$count = $conversion->build();

echo "Created {$count} items.\n";

First, replace example.csv with the path of your spreadsheet. Then, fill in the example_ field map with the names of the appropriate spreadsheet column. To create a Grav page, it's required to have a title, a date, and HTML content.

Finally, run the script! A directory grav will be created with the posts ready to go.

$ php convert.php