Home Convert mediawiki md to jekyll
Post
Cancel

Convert mediawiki md to jekyll

Once its be exported from mediawiki to markdown, use this script to nudge it into jekyll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash

# Set source and destination directories
src_dir="/path/to/source/directory"
dest_dir="/path/to/destination/directory"

# Make sure destination directory exists
mkdir -p "$dest_dir"

# Loop through all .md files in the source directory
for file in "$src_dir"/*.md; do
  # Get the filename without the extension
  filename=$(basename "$file" .md)

  # Create a new lowercase filename with no special characters
  new_filename=$(echo "$filename" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^[:alnum:]\.\-]/-/g')

  # Get the current date in the format YYYY-mm-dd HH:MM:SS +0000
  date=$(date -u +"%Y-%m-%d %H:%M:%S +0000")

  # Create the new file path
  new_file="$dest_dir/$(date +%Y-%m-%d)-${new_filename}.md"

  # Add header section to the new file
  echo -e "---\ntitle: $new_filename\ndate: '$date'\ncategories:\n- $new_filename\ntags:\n- $new_filename\n---\n\n" > "$new_file"

  # Copy the file to the destination directory
  cat "$file" >> "$new_file"
done
This post is licensed under CC BY 4.0 by the author.