Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roberto Alsina
committed
Dec 5, 2017
1 parent
7f948e6
commit 168a5d1
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
What is this? | ||
------------- | ||
|
||
This plugin lets integrate Nikola with a DatoCMS site, thus allowing you to use | ||
a web UI to create and edit posts and pages. | ||
|
||
How to Use it | ||
------------- | ||
|
||
0. Setup your Dato site using the [Nikola template](https://dashboard.datocms.com/account/sites/template?name=Nikola&siteId=4150) | ||
1. Install the plugin using ``nikola plugin -i datocms`` | ||
2. Install the Dato CMS client inside your site using the [instructions](https://docs.datocms.com/other/basic-usage.html) | ||
|
||
You only need to get as far as running the dato command and getting an error about a missing ``dato.config.js`` | ||
|
||
3. Obtain a read-only token following [the same instructions](https://docs.datocms.com/other/basic-usage.html) | ||
and put it in a ``.env`` file (be sure not to commit it to GitHub or something like that :-) | ||
|
||
4. In your conf.py add ``dato/posts`` to ``POSTS`` and ``dato/pages`` to ``PAGES``. **DO NOT USE YOUR REGULAR POSTS/PAGES folders, Dato deletes the contents of those folders!!!!** | ||
|
||
5. Run ``nikola datocms`` | ||
|
||
At that point your pages and posts created in Dato should be ready for you to use. Have fun! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# In order to use DatoCMS you need to add the dato/posts and dato/pages | ||
# folders to your POSTS and PAGES settings | ||
|
||
POSTS = ( | ||
... | ||
("dato/posts/*.md", "posts", "post.tmpl"), | ||
) | ||
PAGES = ( | ||
... | ||
("dato/pages/*.md", "stories", "story.tmpl"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Core] | ||
Name = datocms | ||
Module = datocms | ||
|
||
[Nikola] | ||
PluginCategory = Command | ||
|
||
[Documentation] | ||
Author = Roberto Alsina | ||
Version = 0.1 | ||
Website = http://plugins.getnikola.com/#datocms | ||
Description = Import posts and pages from DatoCMS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright © 2017 Roberto Alsina and others. | ||
|
||
# Permission is hereby granted, free of charge, to any | ||
# person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the | ||
# Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the | ||
# Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice | ||
# shall be included in all copies or substantial portions of | ||
# the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
from __future__ import print_function, unicode_literals | ||
|
||
import os | ||
from nikola.plugin_categories import Command | ||
from nikola import utils | ||
|
||
DATO_CONFIG = ''' | ||
// dato.config.js | ||
module.exports = (dato, root, i18n) => { | ||
root.directory("dato/posts", (postsDir) => { | ||
// ...iterate over the "Blog post" records... | ||
dato.posts.forEach((post) => { | ||
// ...and create a markdown file for each article! | ||
postsDir.createPost( | ||
`${post.slug}.md`, "yaml", { | ||
frontmatter: { | ||
title: post.title, | ||
date: post.date, | ||
tags: post.tags, | ||
author: post.author, | ||
description: post.description, | ||
category: post.category, | ||
}, | ||
content: post.content | ||
} | ||
); | ||
}); | ||
}); | ||
root.directory("dato/pages", (pagesDir) => { | ||
// ...iterate over the "Pages" records... | ||
dato.pages.forEach((page) => { | ||
// ...and create a markdown file for each article! | ||
pagesDir.createPost( | ||
`${page.slug}.md`, "yaml", { | ||
frontmatter: { | ||
title: page.title, | ||
author: page.author, | ||
description: page.description, | ||
}, | ||
content: page.content | ||
} | ||
); | ||
}); | ||
}); | ||
}; | ||
''' | ||
|
||
LOGGER = utils.get_logger('import_blogger', utils.STDERR_HANDLER) | ||
|
||
|
||
class CommandDatoCMS(Command): | ||
"""Import the DatoCMS dump.""" | ||
|
||
name = "datocms" | ||
needs_config = True | ||
doc_usage = "" | ||
doc_purpose = "import the DatoCMS dump" | ||
|
||
def _execute(self, options, args): | ||
"""Import posts and pages from DatoCMS.""" | ||
if not os.path.exists('dato.config.js'): | ||
with open('dato.config.js') as outf: | ||
outf.write(DATO_CONFIG) | ||
os.system('./node_modules/.bin/dato dump') |