fixed tag_index template. moving shared files into shared folder and trying to load from there. then need to build __main__ so that we can run everything at once. CSS needs improvements too.

This commit is contained in:
Anish Lakhwara 2022-02-03 14:44:36 +10:00
parent 649ac8860d
commit d47cc8901f
6 changed files with 17 additions and 89 deletions

View file

@ -1,79 +0,0 @@
from ctags import CTags, TagEntry
import sys
from icecream import ic
from os import listdir, path
# TODO don't hardcode the path
def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'):
# Available file information keys:
# opened - was the tag file successfully opened?
# error_number - errno value when 'opened' is false
# format - format of tag file (1 = original, 2 = extended)
# sort - how is the tag file sorted?
# author - name of author of generating program (may be empy string)
# name - name of program (may be empy string)
# url - URL of distribution (may be empy string)
# version - program version (may be empty string)
try:
tagFile = CTags(path)
return tagFile
except:
print("No tagfile at {}".format(path))
sys.exit(1)
def makeSetFromTags(tagFile, key='file'):
# Available TagEntry keys:
# name - name of tag
# file - path of source file containing definition of tag
# pattern - pattern for locating source line (None if no pattern)
# lineNumber - line number in source file of tag definition (may be zero if not known)
# kind - kind of tag (none if not known)
# fileScope - is tag of file-limited scope?
# Note: other keys will be assumed as an extension key and will
# return None if no such key is found
entry = TagEntry()
tag = tagFile.next(entry)
AllFileList = set()
while tag:
AllFileList.add(entry[key].decode())
tag = tagFile.next(entry)
return AllFileList
def makeDictFromTags(tagFile, key='name', value='file'):
entry = TagEntry()
tag = tagFile.next(entry)
ret = {}
while tag:
# Not sure why they're being read as bytes now?
strKey = entry[key].decode()
strValue = entry[value].decode()
if strKey not in ret.keys():
ret[strKey] = set()
ret[strKey].add(strValue)
else:
ret[strKey].add(strValue)
tag = tagFile.next(entry)
return ret
def getAllFilesWithTags():
# Returns a set containing all the files we wish to make public
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
all_tags = makeDictFromTags(loadTagFile())
all_tags['untagged'] = getUntaggedFiles()
return all_tags

View file

@ -1,5 +1,4 @@
from jinja2 import Environment, FileSystemLoader
import TagHelper
import argparse
import glob
import os
@ -7,13 +6,17 @@ import platform
import re
import shutil
from datetime import datetime
import importlib
# TODO import from shared
TagHelper = importlib.load_module('shared.TagHelper')
# Default encoding
encoding = 'utf-8'
# Import local files
mistune = __import__('mistune')
config = __import__('config')
# TODO import from shared
config = __import__('shared.config')
# Activating the renderer

View file

@ -7,10 +7,10 @@ from os import listdir, mkdir, path, remove
import shutil
import random
import json
import TagHelper
import shared.TagHelper as TagHelper
import convert
from icecream import ic
from censor import privateList
from shared.censor import privateList
## TODO: generalize based on headings(?) in index.wiki

View file

@ -52,15 +52,15 @@ media="screen" title="no title" charset="utf-8">
<h1> {{page_title}} </h1>
<div id='piles' style="float: right;">
<table style="width:100%">
{% set count = 0 %}
<tr>
{% set count = namespace(value=0) %}
{% 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 %}
{% set count.value = count.value + 1 %}
{% if count.value == 5 %}
</tr>
<tr>
{% set count.value = 0 %}
{% endif %}
{% endfor %}
</table>

View file

@ -2,6 +2,7 @@ from ctags import CTags, TagEntry
import sys
from icecream import ic
from os import listdir, path
from shared.censor import privateList
# TODO don't hardcode the path
def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'):
@ -76,4 +77,6 @@ def getAllTags():
# - values as files that have the key in their tags
all_tags = makeDictFromTags(loadTagFile())
all_tags['untagged'] = getUntaggedFiles()
for tag in privateList:
all_tags.pop(tag)
return all_tags

View file

@ -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"