Go to file
Dhananjay Balan 58b20109cf Convert from old categories to tags
import sys
import yaml

with open(sys.argv[1]) as fp:
    data = fp.read()

if not data.find("---") == 0:
    # no head
    print("NO YAML HEAD FOUND")
    sys.exit(-1)

data = data[3:]
head_end = data.find("---")

head = data[0:head_end]
data = data[head_end+3:]

metadata = yaml.safe_load(head)

cats = metadata.pop('categories', None)
if cats != None:
    if type(cats) == list:
        tags = cats
    elif type(cats) == str:
        tags = cats.split()

    tags = list(map(lambda t: t.lower(), tags))

    metadata["tags"] = ", ".join(tags)
    new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}"
    # write it
    print(f"coverted: categories to tags: {tags} - {sys.argv[1]}")
    with open(sys.argv[1], "w") as fp:
        fp.write(new_data)
    sys.exit(0)

if not metadata.get("tags", None):
    metadata["tags"] = "untagged"
    new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}"
    print(f"untagged: {sys.argv[1]}")
    # write it
    with open(sys.argv[1], "w") as fp:
        fp.write(new_data)
    sys.exit(0)

print("No changes needed")
2019-01-28 17:16:27 -05:00
.builds Builds are broken atm. 2019-01-08 16:29:20 -05:00
blog Convert from old categories to tags 2019-01-28 17:16:27 -05:00
css Remove google fonts 2019-01-08 15:22:39 -05:00
fonts Migrate to tufte-css 2017-02-01 11:52:12 +01:00
images Add kuhs blog post 2018-03-08 19:26:15 +01:00
notes Add gpg transition note. 2017-02-13 23:29:23 +01:00
templates Convert from old categories to tags 2019-01-28 17:16:27 -05:00
.gitignore intial commit 2017-01-22 22:30:42 +01:00
blogng.cabal Updated stack and moved to stack 2018-03-05 00:13:59 +01:00
index.html New theme 2019-01-08 15:14:02 -05:00
new_post.py new script to generate blog entries 2017-08-02 12:08:57 +02:00
site.hs Implement Tags! 2019-01-28 16:42:01 -05:00
stack.yaml Bump stack version 2019-01-23 15:59:05 -05:00