I’ve developed a Python script, permalink.py, to streamline the process of creating new posts for various content types on KNX (papers, projects, courses, albums, and blog posts). This script automates several tasks:
Permalink Management:
Extracts existing permalinks from all Markdown files (.md) within the website’s directory.
Stores the extracted permalinks in a file named existing_permalinks.txt in the _plugins directory.
Generates a new, unique permalink that is not already in use.
Post Creation:
Creates a new Markdown file for the specified post type in the appropriate directory (e.g., papers/_posts, projects/_posts, etc.).
Automatically generates the YAML front matter for the post, including the necessary fields for each post type (title, author, tags, etc.).
Includes placeholder content after the YAML front matter, tailored to each post type. For example, paper posts include placeholders for an abstract and keywords, while project posts have sections for a synopsis, acronym explanation, and project description.
Directory Management:
Ensures the necessary directories exist for each post type. If a directory is missing, the script creates it automatically.
Usage:
To use the script, follow these steps:
Save the script: Save the provided Python code as permalink.py in your website’s root directory.
Make it executable: Open your terminal and navigate to the root directory. Then, run the command chmod +x permalink.py to make the script executable.
Run the script: To create a new post, use the following command in your terminal:
Replace <post_type> with: paper, project, course, album, or blog.
Example:
This command creates a new project post with a unique permalink and the following YAML front matter:
And the following placeholder content:
YAML Front Matter and Placeholders:
The script supports different YAML fields and placeholders for each post type. Here’s a summary: