mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-25 10:50:50 +02:00
feat: auto-import Jupyter Notebooks as blog posts
This commit is contained in:
parent
42cbd66239
commit
20f6ecb81f
6 changed files with 149 additions and 180 deletions
54
starters/academic/.github/workflows/import-notebooks.yml
vendored
Normal file
54
starters/academic/.github/workflows/import-notebooks.yml
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Wowchemy GitHub Action to import Jupyter Notebooks as blog posts
|
||||
name: Import Jupyter Notebooks as Blog Posts
|
||||
|
||||
# Require permission to create a PR
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
# Run workflow when a `.bib` file is added or updated in the `data/` folder
|
||||
on:
|
||||
push:
|
||||
branches: ['main']
|
||||
paths: ['notebooks/*.ipynb']
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
wowchemy:
|
||||
if: github.repository_owner != 'wowchemy'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python 3.12
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install academic==0.11.1
|
||||
- name: Run Academic Converter Tool
|
||||
run: academic import 'notebooks/*.ipynb' content/post/ --verbose
|
||||
- name: Create Pull Request
|
||||
# Set ID for `Check outputs` stage
|
||||
id: cpr
|
||||
uses: peter-evans/create-pull-request@v5
|
||||
with:
|
||||
commit-message: 'content: import blog posts from `notebooks/` folder'
|
||||
title: Wowchemy - Import latest blog posts
|
||||
body: |
|
||||
Convert Jupyter Notebooks in the `notebooks/` folder into blog posts in the `content/post/` folder.
|
||||
将`notebooks/`文件夹中的Jupyter笔记本转换为`content/post/`文件夹中的博客帖子。
|
||||
[View Documentation](https://github.com/wowchemy/bibtex-to-markdown)
|
||||
base: main
|
||||
labels: automated-pr, content
|
||||
branch: wowchemy-import-posts
|
||||
delete-branch: true
|
||||
- name: Check outputs
|
||||
if: ${{ steps.cpr.outputs.pull-request-number }}
|
||||
run: |
|
||||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
||||
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
34
starters/academic/content/post/blog-with-jupyter/index.md
Normal file
34
starters/academic/content/post/blog-with-jupyter/index.md
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: Blog with Jupyter Notebooks!
|
||||
date: '2023-11-04'
|
||||
summary: Easily blog from Jupyter notebooks!
|
||||
---
|
||||
|
||||
|
||||
```python
|
||||
from IPython.core.display import Image
|
||||
Image('https://www.python.org/static/community_logos/python-logo-master-v3-TM-flattened.png')
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
```python
|
||||
print("Welcome to Academic!")
|
||||
```
|
||||
|
||||
Welcome to Academic!
|
||||
|
||||
## Organize your notebooks
|
||||
|
||||
Place the notebooks that you would like to publish in a `notebooks` folder at the root of your website.
|
||||
|
||||
## Import the notebooks into your site
|
||||
|
||||
```bash
|
||||
pipx install academic
|
||||
academic import 'notebooks/**.ipynb' content/post/ --verbose
|
||||
```
|
||||
|
||||
The notebooks will be published to the folder you specify above. In this case, they will be published to your `content/post/` folder.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
@ -1,77 +0,0 @@
|
|||
---
|
||||
title: Display Jupyter Notebooks with Academic
|
||||
subtitle: Learn how to blog in Academic using Jupyter notebooks
|
||||
summary: Learn how to blog in Academic using Jupyter notebooks
|
||||
authors:
|
||||
- admin
|
||||
tags: []
|
||||
categories: []
|
||||
projects: []
|
||||
date: '2019-02-05T00:00:00Z'
|
||||
lastMod: '2019-09-05T00:00:00Z'
|
||||
image:
|
||||
caption: ''
|
||||
focal_point: ''
|
||||
---
|
||||
|
||||
```python
|
||||
from IPython.core.display import Image
|
||||
Image('https://www.python.org/static/community_logos/python-logo-master-v3-TM-flattened.png')
|
||||
```
|
||||
|
||||

|
||||
|
||||
```python
|
||||
print("Welcome to Academic!")
|
||||
```
|
||||
|
||||
Welcome to Academic!
|
||||
|
||||
## Install Python and JupyterLab
|
||||
|
||||
[Install Anaconda](https://www.anaconda.com/distribution/#download-section) which includes Python 3 and JupyterLab.
|
||||
|
||||
Alternatively, install JupyterLab with `pip3 install jupyterlab`.
|
||||
|
||||
## Create or upload a Jupyter notebook
|
||||
|
||||
Run the following commands in your Terminal, substituting `<MY-WEBSITE-FOLDER>` and `<SHORT-POST-TITLE>` with the file path to your Academic website folder and a short title for your blog post (use hyphens instead of spaces), respectively:
|
||||
|
||||
```bash
|
||||
mkdir -p <MY-WEBSITE-FOLDER>/content/post/<SHORT-POST-TITLE>/
|
||||
cd <MY-WEBSITE-FOLDER>/content/post/<SHORT-POST-TITLE>/
|
||||
jupyter lab index.ipynb
|
||||
```
|
||||
|
||||
The `jupyter` command above will launch the JupyterLab editor, allowing us to add Academic metadata and write the content.
|
||||
|
||||
## Edit your post metadata
|
||||
|
||||
The first cell of your Jupter notebook will contain your post metadata ([front matter](https://sourcethemes.com/academic/docs/front-matter/)).
|
||||
|
||||
In Jupter, choose _Markdown_ as the type of the first cell and wrap your Academic metadata in three dashes, indicating that it is YAML front matter:
|
||||
|
||||
```
|
||||
---
|
||||
title: My post's title
|
||||
date: 2019-09-01
|
||||
|
||||
# Put any other Academic metadata here...
|
||||
---
|
||||
```
|
||||
|
||||
Edit the metadata of your post, using the [documentation](https://sourcethemes.com/academic/docs/managing-content) as a guide to the available options.
|
||||
|
||||
To set a [featured image](https://sourcethemes.com/academic/docs/managing-content/#featured-image), place an image named `featured` into your post's folder.
|
||||
|
||||
For other tips, such as using math, see the guide on [writing content with Academic](https://wowchemy.com/docs/content/writing-markdown-latex/).
|
||||
|
||||
## Convert notebook to Markdown
|
||||
|
||||
```bash
|
||||
jupyter nbconvert index.ipynb --to markdown --NbConvertApp.output_files_dir=.
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
This post was created with Jupyter. The orginal files can be found at https://github.com/gcushen/hugo-academic/tree/master/exampleSite/content/post/jupyter
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue