Skip to content

Commit

Permalink
draft posts
Browse files Browse the repository at this point in the history
  • Loading branch information
linesinalandscape committed Dec 13, 2024
1 parent f0172d7 commit 6687d18
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4
- name: Generate site
run: |
pip install markdown
pip install markdown2
python3 ssg.py
- name: Setup Pages
uses: actions/configure-pages@v5
Expand Down
2 changes: 1 addition & 1 deletion content/blog/2024-11-30_how-many-hairdressers/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
feature: y
draft: True
description: Thoughts on mapping local pointsof interest in OpenStreetMap.
image:
alt: Screenshot from the CityStrides website, showing a map of GPS traces overlaid over the city of Malaga, with some statistics. Just over 25% of streets have been completed.
Expand Down
2 changes: 1 addition & 1 deletion content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you use a feed reader you can follow this site's [feed](feed.xml) to keep up

### Photography

- [Flickr Photos](https://www.alangrantphoto.com/ "My Flickr Galleries"), my main photo galleries (mostly with photos of Ireland)
- [Flickr Photos](alangrantphoto.com/ "My Flickr Galleries"), my main photo galleries (mostly with photos of Ireland)
- [Flickr Walks](https://www.flickr.com/photos/alangrantphoto/collections/72157721520041495/ "Collection of hiking photos"), a collection of hiking photos
- [Flickr Train Travel](https://www.flickr.com/photos/alangrantphoto/collections/72157721491275251/ "Collection of railway photos"), a collection of railway photography
- [Flickr Places](https://www.flickr.com/photos/alangrantphoto/collections/72157721518635925/ "Collection of travel photos"), travel photography en general
Expand Down
69 changes: 41 additions & 28 deletions ssg.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
'''
TODO
- post titles
- all date related stuff
- date in blog articles
- feed id
- markdown2 in github
- production permalinks
- aria-current?
- paths for feed
- blog index page
- OG images
- reorganise images
- validate html
- check performance
- tags?
- image lazy loading, size?
- 404 check
Expand Down Expand Up @@ -41,7 +34,7 @@
}

SITE_META = {
'site_url': 'http://localhost:8000/',
'site_url': 'test.linesinalandscape.com',
'site_title': 'Lines in a Landscape',
'site_author': 'Alan Grant',
'site_description': 'Trails, trains, maps, Málaga, and more - a personal website'
Expand Down Expand Up @@ -90,11 +83,23 @@ def get_md_data():

# Convert markdown to HTML and store metadata
md_converted = markdown(md, extras=['metadata'])

# reformat internal links
file_data['content'] = str(md_converted).replace('\index.md', '/')
file_data['content'] = str(md_converted)
file_data.update(md_converted.metadata)

# extract the title from the first # line of the markdown file
if 'title' not in file_data:
lines = md.split('\n')
for line in lines:
if line.startswith('# '):
file_data['title'] = line[2:]
break

# check for draft status (any value excep False treated as draft)
if 'draft' in file_data and file_data['draft'] != 'False':
file_data['is_public'] = False
else:
file_data['is_public'] = True

# various metadata fields not already in the markdown file
# set the final url for the page
permalink = (SITE_META.get('site_url')
Expand All @@ -103,13 +108,8 @@ def get_md_data():
permalink = permalink.replace('./', '') # for root index page
file_data['permalink'] = permalink

# extract the title from the first # line of the markdown file
if 'title' not in file_data:
lines = md.split('\n')
for line in lines:
if line.startswith('# '):
file_data['title'] = line[2:]
break
# reformat internal links
file_data['content'] = file_data['content'].replace('\index.md', '/')

# set dates for sorting and feed
if 'date' not in file_data:
Expand Down Expand Up @@ -155,28 +155,41 @@ def process_md_data(md_files):
layouts = load_layouts()

for md_data in md_files:
sitemap_item = ''
index_item = ''
feed_item = ''

html = layouts['html']
sitemap_item = layouts['sitemap_item']
if md_data['is_post']:
if md_data['is_public']:
sitemap_item = layouts['sitemap_item']
if md_data['is_post'] and md_data['is_public']:
index_item = layouts['index_item']
feed_item = layouts['feed_item']
else:
index_item = ''
feed_item = ''


# insert the page metadata into the templates
# exclude if not a string for now
keys = [key for key in md_data if type(md_data[key]) == str]
for key in keys:
html = html.replace('{{ ' + key + ' }}', md_data.get(key))
sitemap_item = (sitemap_item.replace('{{ ' + key + ' }}',
md_data.get(key)))
if md_data['is_post']:
if md_data['is_public']:
sitemap_item = (sitemap_item.replace('{{ ' + key + ' }}',
md_data.get(key)))
if md_data['is_post'] and md_data['is_public']:
index_item = (index_item.replace('{{ ' + key + ' }}',
md_data.get(key)))
feed_item = (feed_item.replace('{{ ' + key + ' }}',
md_data.get(key)))

# set aria-current on navigation link
nav_link = md_data.get('permalink').removeprefix(
SITE_META.get('site_url'))
nav_link = '/' + nav_link.split('/', 1)[0]
if nav_link != '/':
nav_link += '/'
nav_link_html = f'<a href="{nav_link}">'
nav_link_html_new = f'<a href="{nav_link}" aria-current="page">'
html = html.replace(nav_link_html, nav_link_html_new)

# set output file name replacing .md with .html
output_file = Path(md_data['path'].with_suffix('.html'))

Expand Down
1 change: 0 additions & 1 deletion templates/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<header>
<p class="headername">{{ site_title }}</p>
<nav>
<!-- <a href="/" aria-current="page">Home</a> -->
<a href="/">Home</a>
<a href="/blog/">Blog</a>
<a href="/links/">Links</a>
Expand Down

0 comments on commit 6687d18

Please sign in to comment.