move list making into it's own template file, link tags in lists to their index, create untagged index, fix various small bugs
This commit is contained in:
parent
541dad60b0
commit
649ac8860d
|
@ -1,10 +1,7 @@
|
|||
import ctags
|
||||
from ctags import CTags, TagEntry
|
||||
import sys
|
||||
from icecream import ic
|
||||
import os
|
||||
import shutil
|
||||
import fileinput
|
||||
from os import listdir, path
|
||||
|
||||
# TODO don't hardcode the path
|
||||
def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'):
|
||||
|
@ -59,12 +56,24 @@ def makeDictFromTags(tagFile, key='name', value='file'):
|
|||
tag = tagFile.next(entry)
|
||||
return ret
|
||||
|
||||
def getAllFiles():
|
||||
def getAllFilesWithTags():
|
||||
# Returns a set containing all the files we wish to make public
|
||||
return makeSetFromTags(loadTagFile(tagFile))
|
||||
return makeSetFromTags(loadTagFile())
|
||||
|
||||
def getAllFiles():
|
||||
files = [f for f in listdir('/home/anish/vimwiki') if '.wiki' in f and path.isfile('/home/anish/vimwiki/' + f)]
|
||||
files = set(files)
|
||||
return files
|
||||
|
||||
def getUntaggedFiles():
|
||||
allFiles = getAllFiles()
|
||||
allTags = getAllFilesWithTags()
|
||||
return allFiles - allTags
|
||||
|
||||
def getAllTags():
|
||||
# Returns a dictionary with:
|
||||
# - key as tag titles
|
||||
# - values as files that have the key in their tags
|
||||
return makeDictFromTags(loadTagFile())
|
||||
all_tags = makeDictFromTags(loadTagFile())
|
||||
all_tags['untagged'] = getUntaggedFiles()
|
||||
return all_tags
|
||||
|
|
|
@ -35,7 +35,7 @@ if args.prod:
|
|||
def generate_config():
|
||||
pass
|
||||
|
||||
def generate_page(template_file=config.template_file, options=generate_config()):
|
||||
def generate_page(template_file=config.template_main, options=generate_config()):
|
||||
pass
|
||||
|
||||
def generate_navigation(template_nav=config.template_nav):
|
||||
|
@ -54,7 +54,7 @@ def add_file_path(pages, root_dir):
|
|||
return ret
|
||||
|
||||
|
||||
def generate_index_pages(template=config.template_index, template_nav=config.template_nav):
|
||||
def generate_index_pages(template=config.template_main, template_nav=config.template_nav):
|
||||
template = template
|
||||
all_tags = TagHelper.getAllTags()
|
||||
index_tags = config.nav_tags
|
||||
|
@ -63,31 +63,34 @@ def generate_index_pages(template=config.template_index, template_nav=config.tem
|
|||
pages = all_tags[index]
|
||||
pages = add_file_path(pages, config.content_folder[0])
|
||||
entries = create_entries(pages)
|
||||
# TODO this broke as well, not sure what happened to entries, but the whole page is blank?
|
||||
subPages = generate_sub_pages(entries, len(entries), config.content_folder[0], False)
|
||||
metaIndexSubPages.append(generate_sub_pages(entries, 5, config.content_folder[0], True, index))
|
||||
# Build the files by filling out the template
|
||||
file_loader = FileSystemLoader('')
|
||||
env = Environment(loader=file_loader)
|
||||
# regular index pagse use main template
|
||||
template = env.get_template(config.template_file)
|
||||
current_index_template = template.render(page_body=subPages, page_date=None, page_tags=None, page_navigation=generate_navigation(template_nav), page_title='index', config=config)
|
||||
template = env.get_template(template)
|
||||
current_index_template = template.render(page_body=subPages, page_date=None, page_tags=None, page_navigation=generate_navigation(template_nav), page_title=index.capitalize() + ' index', config=config)
|
||||
slugfile = config.build_folder + index + '_index.html'
|
||||
with open(slugfile, 'w', encoding=encoding) as fobj:
|
||||
fobj.write(current_index_template)
|
||||
generate_table_index()
|
||||
|
||||
def generate_table_index(template=config.template_index, template_nav=config.template_nav):
|
||||
# build the metaIndex page
|
||||
# This function creates the tag_index.html page
|
||||
file_loader = FileSystemLoader('')
|
||||
env = Environment(loader=file_loader)
|
||||
template = env.get_template(template)
|
||||
# TODO tag_index subpage is sbroken
|
||||
# create this page by parsing data instead of pages, like untagged below
|
||||
print(metaIndexSubPages)
|
||||
current_index_template = template.render(index_urls=metaIndexSubPages, page_date=None, page_tags=None, page_navigation=generate_navigation(template_nav), page_title='index', config=config)
|
||||
all_tags = TagHelper.getAllTags()
|
||||
parsed_set = {}
|
||||
for k, v in all_tags.items():
|
||||
parsed_set[k] = len(v)
|
||||
current_index_template = template.render(index_urls=parsed_set, page_date=None, page_tags=None, page_navigation=generate_navigation(template_nav), page_title='Piles', config=config)
|
||||
slugfile = config.build_folder + 'tag_index.html'
|
||||
with open(slugfile, 'w', encoding=encoding) as fobj:
|
||||
fobj.write(current_index_template)
|
||||
|
||||
# TODO import TagHelper.get_untagged() and make one of the indexs pages
|
||||
|
||||
|
||||
# Generates html files in the site folder, using the entries and the template.
|
||||
def generate_html_pages(site_folder, entries, template, sub_pages_list, template_nav):
|
||||
|
@ -99,6 +102,8 @@ def generate_html_pages(site_folder, entries, template, sub_pages_list, template
|
|||
file_loader = FileSystemLoader('')
|
||||
env = Environment(loader=file_loader)
|
||||
template = env.get_template(template)
|
||||
if len(entry['tags']) > 1:
|
||||
entry['tags'] = entry['tags'].split(' ')
|
||||
page_template = template.render(page_body=entry['pageContent'], page_date="<date>%s</date>"%entry['date'], page_tags=entry['tags'], naem_of_site="Kitaab", page_navigation=nav_html, page_title=entry['title'], build_url=entry['parent_text'], config=config)
|
||||
|
||||
# Checking if content folder exists
|
||||
|
@ -128,7 +133,7 @@ def get_entry_title(page):
|
|||
if '%title' in textContent:
|
||||
textContent = textContent.replace('%title','')
|
||||
else:
|
||||
textContent = page.split('/')[1].rstrip('.wiki')
|
||||
textContent = page.split('/')[1][:-5] # remove .wiki from the end of the file name
|
||||
except FileNotFoundError:
|
||||
#print(f"Page not found, but present in tags: {page}")
|
||||
return None
|
||||
|
@ -412,38 +417,15 @@ def clean_path(path):
|
|||
|
||||
# Generate the list of sub pages for each section
|
||||
def generate_sub_pages(entries, num, folder, title, title_name=""):
|
||||
|
||||
# Sort entries by date using the iso_date format
|
||||
entries.sort(key=lambda x: x["iso_date"], reverse=True)
|
||||
|
||||
# Take n number of entries (5 for the home, all for the sub-section pages)
|
||||
selected_entries = entries[:num]
|
||||
|
||||
# Create the list
|
||||
sub_page_list = "<ul class='listing'>"
|
||||
for entry in selected_entries:
|
||||
if title:
|
||||
link_url = entry["slug"]
|
||||
else:
|
||||
link_url = entry["file"] + ".html"
|
||||
|
||||
if entry["file"] != "index":
|
||||
entry_string = "<li><div style='overflow: hidden;'><h3 style='float:left;'><a href='" + \
|
||||
link_url + \
|
||||
"'>" + entry["title"] + \
|
||||
"</a> </h3><p style='float:right;'> {} </p> </div> {} </li>".format(entry['date'], entry["tags"])
|
||||
sub_page_list += entry_string
|
||||
sub_page_list += "</ul>"
|
||||
|
||||
# If a title is necessary, use the folder name
|
||||
# This only gets applied for metaIndexSubPages in the generate_index_pages function
|
||||
if title:
|
||||
title = f"<h2><a href={title_name}_index.html>{title_name.capitalize()}</h2>"
|
||||
sub_page_list = title + sub_page_list
|
||||
if config.flat_build:
|
||||
sub_page_link = build_url + title_name + "_index.html"
|
||||
else:
|
||||
sub_page_link = build_url + folder
|
||||
file_loader = FileSystemLoader('')
|
||||
env = Environment(loader=file_loader)
|
||||
template = env.get_template(config.template_list) # TODO maybe not hardcode
|
||||
sub_page_list = template.render(entries=selected_entries, title_name=title_name, title=title)
|
||||
|
||||
return sub_page_list
|
||||
|
||||
|
@ -514,12 +496,15 @@ def generate_website():
|
|||
os.makedirs(config.build_folder + config.medias_folder)
|
||||
|
||||
# Get main html template
|
||||
template = open(config.template_file, 'r').read()
|
||||
home_page = create_home_page(template, config.build_folder)
|
||||
file_loader = FileSystemLoader('')
|
||||
env = Environment(loader=file_loader)
|
||||
home_page = env.get_template(config.template_main) # TODO maybe not hardcode
|
||||
#home_page = create_home_page(template, config.build_folder)
|
||||
|
||||
generate_index_pages(config.template_index, config.template_nav)
|
||||
generate_index_pages(config.template_main, config.template_nav)
|
||||
|
||||
rss_entries = []
|
||||
home_pageSubList = []
|
||||
for folder in config.content_folder:
|
||||
pages = glob.glob(folder + '**/*.wiki', recursive=True)
|
||||
entries = create_entries(pages)
|
||||
|
@ -528,11 +513,11 @@ def generate_website():
|
|||
|
||||
# For each section, create a short listing of sub pages and add it to the home page
|
||||
home_pageSubList = generate_sub_pages(entries, 50, folder, False)
|
||||
home_page = home_page.replace('content_list', home_pageSubList +
|
||||
"content_list")
|
||||
home_page = home_page.replace('page_date', "")
|
||||
#home_page = home_page.replace('content_list', home_pageSubList +
|
||||
# "content_list")
|
||||
#home_page = home_page.replace('page_date', "")
|
||||
|
||||
generate_html_pages(config.build_folder, entries, config.template_file,
|
||||
generate_html_pages(config.build_folder, entries, config.template_main,
|
||||
sub_pages_list, config.template_nav)
|
||||
|
||||
for entry in entries:
|
||||
|
@ -544,12 +529,13 @@ def generate_website():
|
|||
|
||||
# Once all sections have been processed, finish the home page
|
||||
# Removes the "content_list" in the partial
|
||||
home_page = home_page.replace('content_list', "")
|
||||
home_page = home_page.replace('name_of_site', config.name_of_site)
|
||||
home_page = home_page.replace('site_meta_description',
|
||||
config.site_meta_description)
|
||||
home_page = home_page.replace(
|
||||
'twitter_name', config.twitter_name)
|
||||
#home_page = home_page.replace('content_list', "")
|
||||
#home_page = home_page.replace('name_of_site', config.name_of_site)
|
||||
#home_page = home_page.replace('site_meta_description',
|
||||
# config.site_meta_description)
|
||||
#home_page = home_page.replace(
|
||||
# 'twitter_name', config.twitter_name)
|
||||
home_page = home_page.render(page_body=home_pageSubList, page_date=None, page_tags=None, page_navigation=generate_navigation(), page_title="Recent Files", config=config)
|
||||
|
||||
slug_file = config.build_folder + "recents.html"
|
||||
with open(slug_file, 'w', encoding=encoding) as fobj:
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
content_folder = ['raw']
|
||||
nav_tags = ['dev', 'way', 'recipe', 'ops', 'blog', 'rock', 'phil', 'story', 'blog']
|
||||
nav_tags = ['dev', 'way', 'recipe', 'ops', 'blog', 'rock', 'phil', 'story', 'blog', 'untagged']
|
||||
relative_build_url = ""
|
||||
absolute_build_url = "https://anish.lakhwara.com/"
|
||||
files_folder = '' #TODO
|
||||
build_folder = "output/"
|
||||
assets_folder = "asset/"
|
||||
medias_folder = "media/"
|
||||
template_file = "partial/main.html"
|
||||
template_main = "partial/main.html"
|
||||
template_nav = "partial/nav.html"
|
||||
template_index = "partial/index_table.html"
|
||||
template_list = "partial/list.html"
|
||||
rss_template = "partial/rss.xml"
|
||||
rss_item_template = "partial/item.xml"
|
||||
name_of_site = "Kitaab"
|
||||
|
|
|
@ -16,7 +16,7 @@ from censor import privateList
|
|||
|
||||
censor = privateList
|
||||
# TODO put this in config too...
|
||||
filter = ["dream", "gratitude", "review", "jrnl", "piracy", "work", "job", "debt", "people", "priv"]
|
||||
filter = ["dream", "gratitude", "review", "jrnl", "piracy", "work", "job", "debt", "people", "priv", "threatdefence"]
|
||||
#TODO create = ...
|
||||
|
||||
def loadNetwork(path='network.json'):
|
||||
|
|
|
@ -45,13 +45,19 @@ media="screen" title="no title" charset="utf-8">
|
|||
|
||||
<body class="flow-large container">
|
||||
<header>
|
||||
<a href="recents.html" aria-label="{{page_title}}">{{config.name_of_site}}</a>
|
||||
</header>
|
||||
<main>
|
||||
{{page_navigation}}
|
||||
<h1> {{page_title}} </h1>
|
||||
<div id='piles' style="float: right;">
|
||||
<table style="width:100%">
|
||||
{% set count = 0 %}
|
||||
<tr>
|
||||
{% for index_url in index_urls %}
|
||||
<td>{{index_url}}</td>
|
||||
{% for index_url, c in index_urls.items() %}
|
||||
<td> <a href="{{index_url}}_index.html">{{index_url}}</a> {{c}}</td>
|
||||
{% set count = count + 1 %}
|
||||
{{count}}
|
||||
{% if count == 5 %}
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
32
src/kitaab-public/partial/list.html
Normal file
32
src/kitaab-public/partial/list.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% if title %}
|
||||
<h2><a href={{title_name}}_index.html>{{title_name.capitalize()}}</a></h2>
|
||||
{% endif %}
|
||||
<ul class='listing'>
|
||||
{% for entry in entries %}
|
||||
<li>
|
||||
<div style='overflow: hidden;'>
|
||||
<h3 style='float:left;'>
|
||||
{% if title %}
|
||||
<a href='{{entry['slug']}}'>{{entry["title"]}}</a>
|
||||
{% else %}
|
||||
<!--
|
||||
TODO
|
||||
Sometimes the entry doesn't output a title and I'm not entirely sure why
|
||||
--!>
|
||||
{% if entry['title'] %}
|
||||
<a href='{{entry['file']}}.html'>{{entry["title"]}}</a>
|
||||
{% else %}
|
||||
<a href='{{entry['file']}}.html'>{{entry['file']}}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p style='float:right;'>{{entry['date']}}</p>
|
||||
</div>
|
||||
{% for page in entry['tags'].split(' ') %}
|
||||
<a href="{{page}}_index.html">
|
||||
{{page}}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
|
@ -45,15 +45,23 @@ media="screen" title="no title" charset="utf-8">
|
|||
|
||||
<body class="flow-large container">
|
||||
<header>
|
||||
<a href="home.html" aria-label="{{page_title}}">{{config.name_of_site}}</a>
|
||||
<a href="home.html" aria-label="{{config.name_of_site}}">{{config.name_of_site}}</a>
|
||||
</header>
|
||||
<main>
|
||||
{{ page_navigation }}
|
||||
<h1> {{page_title}} </h1>
|
||||
<div style='max-width:460px;'>
|
||||
<article class="flow">
|
||||
{{page_tags}}
|
||||
{% if page_tags %}
|
||||
{% for page in page_tags %}
|
||||
<a href="{{page}}_index.html">
|
||||
{{page}}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if page_date %}
|
||||
{{page_date}}
|
||||
{% endif %}
|
||||
{{page_body}}
|
||||
</article>
|
||||
</div>
|
||||
|
|
|
@ -56,7 +56,7 @@ def makeDictFromTags(tagFile, key='name', value='file'):
|
|||
tag = tagFile.next(entry)
|
||||
return ret
|
||||
|
||||
def getAllFilesWithTgas():
|
||||
def getAllFilesWithTags():
|
||||
# Returns a set containing all the files we wish to make public
|
||||
return makeSetFromTags(loadTagFile())
|
||||
|
||||
|
@ -65,8 +65,15 @@ def getAllFiles():
|
|||
files = set(files)
|
||||
return files
|
||||
|
||||
def getUntaggedFiles():
|
||||
allFiles = getAllFiles()
|
||||
allTags = getAllFilesWithTags()
|
||||
return allFiles - allTags
|
||||
|
||||
def getAllTags():
|
||||
# Returns a dictionary with:
|
||||
# - key as tag titles
|
||||
# - values as files that have the key in their tags
|
||||
return makeDictFromTags(loadTagFile())
|
||||
all_tags = makeDictFromTags(loadTagFile())
|
||||
all_tags['untagged'] = getUntaggedFiles()
|
||||
return all_tags
|
21
src/kitaab-public/shared/config.py
Normal file
21
src/kitaab-public/shared/config.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
content_folder = ['raw']
|
||||
nav_tags = ['dev', 'way', 'recipe', 'ops', 'blog', 'rock', 'phil', 'story', 'blog']
|
||||
relative_build_url = ""
|
||||
absolute_build_url = "https://anish.lakhwara.com/"
|
||||
files_folder = '' #TODO
|
||||
build_folder = "output/"
|
||||
assets_folder = "asset/"
|
||||
medias_folder = "media/"
|
||||
template_file = "partial/main.html"
|
||||
template_nav = "partial/nav.html"
|
||||
template_index = "partial/index_table.html"
|
||||
rss_template = "partial/rss.xml"
|
||||
rss_item_template = "partial/item.xml"
|
||||
name_of_site = "Kitaab"
|
||||
site_meta_description = ""
|
||||
twitter_name = "@aynish@merveilles.town"
|
||||
home_name = "Home"
|
||||
see_all = "See more"
|
||||
go_back = "Go back to"
|
||||
date_format = "EU" # Choose between EU day-month-year or ISO year-mont-day
|
||||
flat_build = True # True or False, if True, all files will be written in the root of the website
|
Loading…
Reference in a new issue