Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
_site
.sass-cache
Gemfile.lock
# Python
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/

# Jekyll
_site/
.sass-cache/
.jekyll-cache/
.jekyll-metadata

# Development environments
.env
.venv
venv/
ENV/

# IDEs and editors
.idea/
.vscode/
*.swp
*.swo
*~

# Dependency directories
node_modules/
jspm_packages/

# Build output
dist/
build/

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Miscellaneous
.DS_Store
Thumbs.db
Binary file not shown.
Binary file not shown.
Binary file added __pycache__/update_post_authors.cpython-312.pyc
Binary file not shown.
11 changes: 9 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ baseurl: "/" # The subpath of your site. Use "" if you're hosting a blog at the
url: "http://ellekasai.github.io" # the base hostname & protocol for your site
title: "Co-Lab"

# Author configuration
author:
name: "Anonymous"
bio: "Default site author"
avatar: "/images/default-avatar.jpg"

# This is used by feed.xml. Uncomment if you want to use it.
# description: "..."

Expand All @@ -27,7 +33,8 @@ defaults:
type: "posts"
values:
layout: "post"
author: "Anonymous"

# Excerpt settings
excerpt_separator: <!--more-->
show_excerpts: true
excerpt_separator: <!--more-->"
show_excerpts: true
60 changes: 18 additions & 42 deletions _layouts/post.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
---
layout: default
---

<div class="post-header">
<h1 class="post-title-main">{{ page.title }}</h1>
{% include post-header.html %}
</div>
<div class="post-content">
{{ content }}
</div>
<div class="post-footer">
{% include post-footer.html %}
</div>
{% if site.data.theme.show_post_navs %}
{% if page.previous or page.next %}
<div class="post-navs">
{% if page.previous %}
<div class="post-nav">
<h3 class="section-header">
Older
<span class="text-muted"> &middot; </span>
<a href="{{ "/archive" }}">View Archive ({{ site.posts.size }})</a>
</h3>
<h2 class="post-title-link"><a href="{{ page.previous.url }}">{{ page.previous.title }}</a></h2>
{% assign prev_excerpt = page.previous.content | replace: '_By Al Morris_', '' | replace: 'By Al Morris', '' | replace: '*By Al Morris*', '' | strip_html | truncatewords: 25 %}
<p>{{ prev_excerpt }}</p>
</div>
{% endif %}
{% if page.next %}
<div class="post-nav" {% if page.previous %}style="margin-top: 30px;"{% endif %}>
<h3 class="section-header">
Newer
{% unless page.previous %}
<span class="text-muted"> &middot; </span>
<a href="{{ "/archive" }}">View Archive ({{ site.posts.size }})</a>
{% endunless %}
</h3>
<h2 class="post-title-link"><a href="{{ page.next.url }}">{{ page.next.title }}</a></h2>
{% assign next_excerpt = page.next.content | replace: '_By Al Morris_', '' | replace: 'By Al Morris', '' | replace: '*By Al Morris*', '' | strip_html | truncatewords: 25 %}
<p>{{ next_excerpt }}</p>
</div>
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
<p class="post-meta">
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
{{ page.date | date: "%b %-d, %Y" }}
</time>
{% if page.author %}
• <span itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">{{ page.author }}</span>
</span>
{% endif %}
</div>
{% endif %}
{% endif %}
</p>
</header>

<div class="post-content" itemprop="articleBody">
{{ content }}
</div>
</article>
40 changes: 40 additions & 0 deletions test_update_post_authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import re
import unittest
from update_post_authors import update_post_frontmatter

class TestPostAuthorUpdate(unittest.TestCase):
def setUp(self):
# Create a temporary test markdown file
self.test_file = '_posts/test_post.md'
with open(self.test_file, 'w') as f:
f.write('''---
layout: post
title: Test Post
date: 2024-01-01
---
Test content''')

def test_update_frontmatter(self):
update_post_frontmatter(self.test_file)

# Read the updated file
with open(self.test_file, 'r') as f:
content = f.read()

# Use regex to parse front matter
front_matter_match = re.match(r'^---\n(.*?\n)---', content, re.DOTALL)
self.assertIsNotNone(front_matter_match)

front_matter = front_matter_match.group(1)

# Check author is added
self.assertIn('author: Anonymous', front_matter)

def tearDown(self):
# Remove test file
if os.path.exists(self.test_file):
os.remove(self.test_file)

if __name__ == '__main__':
unittest.main()
39 changes: 39 additions & 0 deletions update_post_authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import re

def update_post_frontmatter(file_path):
with open(file_path, 'r') as f:
content = f.read()

# Regex to handle front matter parsing
front_matter_match = re.match(r'^---\n(.*?\n)---', content, re.DOTALL)

if front_matter_match:
front_matter = front_matter_match.group(1)

# Check if author is already present
if 'author:' not in front_matter:
# Add author line
updated_front_matter = front_matter.rstrip() + '\nauthor: Anonymous\n'

# Replace the original front matter
updated_content = re.sub(
r'^---\n.*?---',
f'---\n{updated_front_matter}---',
content,
flags=re.DOTALL
)

with open(file_path, 'w') as f:
f.write(updated_content)
print(f"Updated {file_path} with default author")

def main():
posts_dir = '_posts'
for filename in os.listdir(posts_dir):
if filename.endswith('.md'):
file_path = os.path.join(posts_dir, filename)
update_post_frontmatter(file_path)

if __name__ == '__main__':
main()