diff --git a/src/kitaab-public/build/TagHelper.py b/src/kitaab-public/build/TagHelper.py deleted file mode 100644 index 5ec28f2..0000000 --- a/src/kitaab-public/build/TagHelper.py +++ /dev/null @@ -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 diff --git a/src/kitaab-public/build/build.py b/src/kitaab-public/build/build.py index d45f7ed..ddbee5b 100644 --- a/src/kitaab-public/build/build.py +++ b/src/kitaab-public/build/build.py @@ -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 diff --git a/src/kitaab-public/grab/makePublic.py b/src/kitaab-public/grab/makePublic.py index 701fce8..1250522 100644 --- a/src/kitaab-public/grab/makePublic.py +++ b/src/kitaab-public/grab/makePublic.py @@ -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 diff --git a/src/kitaab-public/partial/index_table.html b/src/kitaab-public/partial/index_table.html index 60eb0a9..e1e81b1 100644 --- a/src/kitaab-public/partial/index_table.html +++ b/src/kitaab-public/partial/index_table.html @@ -52,15 +52,15 @@ media="screen" title="no title" charset="utf-8">

{{page_title}}

- {% set count = 0 %} + {% set count = namespace(value=0) %} {% for index_url, c in index_urls.items() %} - {% set count = count + 1 %} - {{count}} - {% if count == 5 %} + {% set count.value = count.value + 1 %} + {% if count.value == 5 %} + {% set count.value = 0 %} {% endif %} {% endfor %}
{{index_url}} {{c}}
diff --git a/src/kitaab-public/shared/TagHelper.py b/src/kitaab-public/shared/TagHelper.py index 5ec28f2..528e5e1 100644 --- a/src/kitaab-public/shared/TagHelper.py +++ b/src/kitaab-public/shared/TagHelper.py @@ -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 diff --git a/src/kitaab-public/shared/config.py b/src/kitaab-public/shared/config.py index 19dc6e6..2ef5493 100644 --- a/src/kitaab-public/shared/config.py +++ b/src/kitaab-public/shared/config.py @@ -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"