LoginSignup
10
6

More than 5 years have passed since last update.

Jupyter Notebookをブログの記事しとして投稿する

Posted at

前回の続きです。

前回はNikolaのデフォルト形式であるreStructuredText形式とMarkdown形式を使ってブログを投稿しました。
今回はipynb形式(Jupyter Notebook)を使ってブログを投稿してみます。

準備

サイトディレクトリ直下にあるconf.pyを編集します。拡張子 ipynb のエントリを追加します。

  • 編集前
conf.py
POSTS = (
    ("posts/*.rst", "posts", "post.tmpl"),
    ("posts/*.md", "posts", "post.tmpl"),
    ("posts/*.txt", "posts", "post.tmpl"),
    ("posts/*.html", "posts", "post.tmpl"),
)
PAGES = (
    ("pages/*.rst", "pages", "page.tmpl"),
    ("pages/*.md", "pages", "page.tmpl"),
    ("pages/*.txt", "pages", "page.tmpl"),
    ("pages/*.html", "pages", "page.tmpl"),
)
  • 編集後
conf.py
POSTS = (
    ("posts/*.rst", "posts", "post.tmpl"),
    ("posts/*.md", "posts", "post.tmpl"),
    ("posts/*.txt", "posts", "post.tmpl"),
    ("posts/*.html", "posts", "post.tmpl"),
    ("posts/*.ipynb", "posts", "post.tmpl"),
)
PAGES = (
    ("pages/*.rst", "pages", "page.tmpl"),
    ("pages/*.md", "pages", "page.tmpl"),
    ("pages/*.txt", "pages", "page.tmpl"),
    ("pages/*.html", "pages", "page.tmpl"),
    ("pages/*.ipynb", "pages", "page.tmpl"),
)

投稿

下記のコマンドを実行します。

nikola new_post -f ipynb
Creating New Post
-----------------

Title:

記事のタイトルを入力すると、 post/タイトル名.ipynb ファイルが生成されます。
このファイルをJupyter上で編集します。

ビルドと確認

ビルドは前回と同じです。

nikola build
nikola serve -b

このような感じで投稿されます。

image.png

既に作成されたipynbファイルから投稿

  • ipynbファイルは サイトのディレクトリ/post 直下におきます。
  • Jupyter Notebook上から menu bar - Edit - Edit Notebook Metadata を選択し、下記のようなエントリを追加します。 "nikola": は固定で、タイトル等は記事に合わせて変更します。
  "nikola": {
    "tags": "",
    "title": "post4",
    "date": "2017-06-17 15:15:00 UTC+09:00",
    "type": "text",
    "slug": "post4",
    "category": "",
    "link": "",
    "description": ""
  }
  • Notebookの中身を入力して保存します。
  • 前述と同じ方法でビルドします。
nikola build
nikola serve -b

image.png

このように、Notebookのメタデータを追加するだけで、ブログの記事として投稿ができます。

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6