Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

набросаны теги #277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion blogit
Expand Up @@ -67,6 +67,16 @@ def makeHtml(inbound):
res = re.sub('\{([a-zA-Z0-9\*]+)\}', tags_cludge, res)
return res

def getTags(entry):
tags = {}
for line in entry.content.split('\n'):
line = line.strip()
tagsFinded = re.findall(" \#([a-zA-Z0-9\*]+)", line) + re.findall("\{([a-zA-Z0-9\*]+)\}", line)
for tag in tagsFinded:
tags[tag] = tags.get(tag,[])
tags[tag].append({'page' : entry.page, 'line' : line})
return tags

def extract_numbers(s):
s = s.replace('.md', '')
num = ''.join((x for x in s if x.isdigit()))
Expand Down Expand Up @@ -164,6 +174,7 @@ class MarkDownEntry(Entry):
title, rest = self.content.split('\n', 1)
self.title = title
self.content = rest
self.tags = getTags(self)
self.content = makeHtml(self.content)
self.result = os.path.join(config['local']['results']['posts'],
self.page, 'index.html')
Expand Down Expand Up @@ -203,7 +214,8 @@ class Archive:
'conf': config,
'title': 'Archive',
'items': items,
'permalink': config['site'] + '/archive'
'permalink': config['site'] + '/archive',
'tags': self.idx['tags'].values()
})
with saveto(self.results) as fl:
fl.write(res)
Expand Down Expand Up @@ -465,13 +477,18 @@ def regen(wipe=False, force=False, noindex=False, andsync=False, sections=False)
"""regenerate index and all pages"""
cache = Index(ro=True)
with Index() as idx:
tags = {}
if wipe:
idx['idx'] = []
cache['idx'] = []
for item in os.listdir(config['local']['posts']):
entry = gen_page(page=item, force=force, index=cache)
if entry:
put_to_index(index=idx, entry=entry)
for tag in entry.tags:
tags[tag] = tags.get(tag, {'name': tag, 'hits': []})
tags[tag]['hits'] = tags[tag]['hits'] + entry.tags[tag]
idx['tags'] = tags
if sections:
for item in os.listdir(config['local']['section']):
entry = gen_section(page=item)
Expand Down
11 changes: 11 additions & 0 deletions source/templates/archive.mustache
Expand Up @@ -88,6 +88,17 @@
<li><a href="{{ fname }}">{{ subtitle }}</a></li>
{{/items }}
</ul>
<h2>Tags</h2>
<ul>
{{#tags}}
<li>{{name}}</li>
<ul>
{{#hits}}
<li>{{page}} {{line}}</li>
{{/hits}}
</ul>
{{/tags}}
</ul>
</article>

<hr>
Expand Down