working clean build

This commit is contained in:
Anish Lakhwara 2022-04-14 23:40:38 +10:00
parent 85b2750204
commit e787a657a7
4 changed files with 29 additions and 21 deletions

View file

@ -101,6 +101,7 @@ def generate_table_index(template=config.template_index, template_nav=config.tem
page_navigation=generate_navigation( page_navigation=generate_navigation(
template_nav), template_nav),
page_title='Piles', page_title='Piles',
head=generate_head(),
config=config) config=config)
slugfile = config.build_folder + 'tag_index.html' slugfile = config.build_folder + 'tag_index.html'
with open(slugfile, 'w', encoding=encoding) as fobj: with open(slugfile, 'w', encoding=encoding) as fobj:
@ -121,6 +122,7 @@ def generate_html_pages(site_folder, entries, template, sub_pages_list, template
if len(entry['tags']) > 1: if len(entry['tags']) > 1:
entry['tags'] = entry['tags'].split(' ') entry['tags'] = entry['tags'].split(' ')
page_template = template.render( page_template = template.render(
head=generate_head(page_title=entry['title']),
page_body=entry['pageContent'], page_body=entry['pageContent'],
page_date="<date>%s</date>" % entry['date'], page_date="<date>%s</date>" % entry['date'],
page_tags=entry['tags'], page_tags=entry['tags'],
@ -283,7 +285,6 @@ def remove_date(page):
page = re.sub(regex, '', page) page = re.sub(regex, '', page)
return page return page
except Exception as e: except Exception as e:
print(e)
print(f'Unexpected error in removing date in {page}') print(f'Unexpected error in removing date in {page}')
return page return page
@ -417,7 +418,7 @@ def clean_path(path):
"slug": None, "slug": None,
"date": None, "date": None,
"folder": items[0], "folder": items[0],
"file": items[1] "file": items[len(items) - 1]
} }
# xx-xx-xxxx = xx-xx-xxxx.html # xx-xx-xxxx = xx-xx-xxxx.html
@ -499,10 +500,11 @@ def generate_sub_pages(entries, num, folder, title, title_name=""):
# Create the list # Create the list
file_loader = FileSystemLoader('') file_loader = FileSystemLoader('')
env = Environment(loader=file_loader) env = Environment(loader=file_loader)
# TODO maybe not hardcode
template = env.get_template(config.template_list) template = env.get_template(config.template_list)
sub_page_list = template.render( sub_page_list = template.render(
entries=selected_entries, title_name=title_name, title=title) entries=selected_entries,
title_name=title_name,
title=title)
return sub_page_list return sub_page_list
@ -533,8 +535,8 @@ def create_rss_feed(rss_entries, rss_template, rss_item_template, site_folder):
entry_template = itemTemplate entry_template = itemTemplate
entry_template = entry_template.replace( entry_template = entry_template.replace(
'rssItemTitle', rss_entry["title"]) 'rssItemTitle', rss_entry["title"])
entry_template = entry_template.replace('rssItemUrl', build_url entry_template = entry_template.replace('rssItemUrl', build_url +
+ rss_entry["slug"]) rss_entry["slug"])
entry_template = entry_template.replace( entry_template = entry_template.replace(
'rssItemDate', rss_entry["iso_date"]) 'rssItemDate', rss_entry["iso_date"])
entry_template = entry_template.replace( entry_template = entry_template.replace(

View file

@ -1,12 +1,12 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{page_title}} | {{config.name_of_site}}</title> <title>{{page_title}} | {{name_of_site}}</title>
<meta property="og:title" content="{{page_title}} | {{config.name_of_site}}"> <meta property="og:title" content="{{page_title}} | {{name_of_site}}">
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:description" <meta property="og:description"
content="config.site_meta_description"> content="site_meta_description">
<meta property="og:site_name" content="{{config.name_of_site}}"> <meta property="og:site_name" content="{{name_of_site}}">
<meta property="og:url" content="{{build_url}}"> <meta property="og:url" content="{{build_url}}">
<meta property="og:image" content="assets/social.png"> <meta property="og:image" content="assets/social.png">
<meta property="og:image:height" content="300"> <meta property="og:image:height" content="300">

View file

@ -52,30 +52,35 @@ def makeSetFromTags(tagFile, key='file'):
def makeDictFromTags(tagFile, key='name', value='file'): def makeDictFromTags(tagFile, key='name', value='file'):
entry = TagEntry() entry = TagEntry()
tag = tagFile.next(entry) tag = tagFile.next(entry)
allFiles = getAllFiles()
ret = {} ret = {}
while tag: while tag:
# Not sure why they're being read as bytes now? # Not sure why they're being read as bytes now?
strKey = entry[key].decode() strKey = entry[key].decode()
strValue = entry[value].decode() strValue = entry[value].decode()
if strValue in allFiles:
if strKey not in ret.keys(): if strKey not in ret.keys():
ret[strKey] = set() ret[strKey] = set()
ret[strKey].add(strValue) ret[strKey].add(strValue)
else: else:
ret[strKey].add(strValue) ret[strKey].add(strValue)
else:
print(f"found only tag {strValue}")
tag = tagFile.next(entry) tag = tagFile.next(entry)
return ret return ret
def getAllFilesWithTags(): def getAllFilesWithTags():
# Returns a set containing all the files we wish to make public # Returns a set containing all the files we wish to make public
return makeSetFromTags(loadTagFile()) ret = makeSetFromTags(loadTagFile())
allFiles = getAllFiles()
onlyTags = ret - allFiles
return ret - onlyTags
def getUntaggedFiles(): def getUntaggedFiles():
allFiles = getAllFiles() allFiles = getAllFiles()
allTags = getAllFilesWithTags() allTags = getAllFilesWithTags()
print("All tags from untagged")
print(allTags)
return allFiles - allTags return allFiles - allTags
@ -84,5 +89,6 @@ def getAllTags():
# - key as tag titles # - key as tag titles
# - values as files that have the key in their tags # - values as files that have the key in their tags
all_tags = makeDictFromTags(loadTagFile()) all_tags = makeDictFromTags(loadTagFile())
print(f"untagged: {getUntaggedFiles()}")
all_tags['untagged'] = getUntaggedFiles() all_tags['untagged'] = getUntaggedFiles()
return all_tags return all_tags

View file

@ -50,11 +50,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1649938384, "lastModified": 1649943612,
"narHash": "sha256-VZUS7k1NFszRpvvpZKgswF3dlv72DvkRyNrir7RLlus=", "narHash": "sha256-SDpQSBgNkfpBCIFnwH7gtDi+Ip0/3QdlGmiumM6W5xA=",
"ref": "main", "ref": "main",
"rev": "b96c3ee8a8d1b9b83b2a27e6fc6100f3c2cf8bcc", "rev": "c18b26c49ece10fbd770d8422661c34363ecc199",
"revCount": 304, "revCount": 308,
"type": "git", "type": "git",
"url": "ssh://gitea@git.sealight.xyz/aynish/kitaab" "url": "ssh://gitea@git.sealight.xyz/aynish/kitaab"
}, },