This Python script extracts posts from a Ghost blog SQLite database and generates individual HTML pages for each post. It also creates an index page with a list of links to the extracted posts. The extracted pages can be used for offline browsing or to migrate content to another platform.
- Python 3.x
- SQLite3 library (included in Python standard library)
- Jinja2 library (can be installed via
pip install Jinja2)
-
Ensure you have a backup of your Ghost blog database in SQLite format (
ghost.db). -
Place the
ghost.dbin a local directory accessible from the script direcotry. -
Update
index_template.htmlandpage_template.htmlto your liking (like copyright in footer!) -
Open a terminal or command prompt and navigate to the script directory.
-
Run the script with the following command:
python extract_posts.py ../path/to/ghost.db
Replace ../path/to/ghost.db with the actual name of your SQLite database.
-
The script will create an
outdirectory (if it doesn't already exist) and generate individual HTML pages for each post inside theoutdirectory. -
It will also generate an
index.htmlfile in theoutdirectory, which contains a list of links to the extracted posts. -
To preview the generated pages run the following command:
python -m http.server -d out
This will start a local web server. Open your web browser and visit http://localhost:8000 to view the extracted pages.
- You can customize the HTML templates for individual posts and the index page by modifying the respective template files (
template.htmlandindex_template.html). Make sure to update the script with the correct paths to these template files.
-
Ensure that the necessary images, or any other external assets referenced in the HTML templates are also included in the appropriate directories within the
outdirectory for proper rendering. -
The script uses the Jinja2 template engine to render the HTML templates. Please refer to the Jinja2 documentation (https://jinja.palletsprojects.com/) for more information on template syntax and features.
-
This script assumes a certain database schema for Ghost blog. If your database schema is different, you may need to modify the script accordingly.
-
Always make a backup of your database before running the script to avoid any accidental data loss.
-
This script and description was made with a help of ChatGPT. If you are intrested in the process here is the transcript

