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.db
in a local directory accessible from the script direcotry. -
Update
index_template.html
andpage_template.html
to 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
out
directory (if it doesn't already exist) and generate individual HTML pages for each post inside theout
directory. -
It will also generate an
index.html
file in theout
directory, 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.html
andindex_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
out
directory 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