Let permute take the pool first to remove blank first arg.

This commit is contained in:
Ethan Dalool 2020-07-29 11:30:10 -07:00
parent 59e9c98508
commit 1fcf786e22

View file

@ -263,40 +263,36 @@ def remove_redundant(query):
seen.update(tag.walk_parents()) seen.update(tag.walk_parents())
return newq return newq
def permute(query, pool): def permute(pool, query=tuple()):
if query: if query:
query = remove_redundant(query) query = remove_redundant(query)
if complete_tag_index.get(query): if complete_tag_index.get(query):
return return
articles = list(P.search(tag_musts=query)) articles = list(P.search(tag_musts=query))
if not articles: if not articles:
return return
articles = [ARTICLES[article.real_path] for article in articles] articles = [ARTICLES[article.real_path] for article in articles]
# Only generate a page for this tag query if it contains different
# results from the previous query. For example, if an article has tags
# A, B, and C, but it is the only article with those tags, there's no
# reason to generate tag pages for /A, /A/B, /A/B/C, all of which have
# the same single result.
if len(query) > 1: if len(query) > 1:
previous = query[:-1] previous = query[:-1]
prevarticles = complete_tag_index.get(previous) prevarticles = complete_tag_index.get(previous)
# print(f'''
# query={query},
# docs={docs}
# previous={previous},
# prevdocs={prevdocs},
# ''')
if set(articles) == set(prevarticles): if set(articles) == set(prevarticles):
return return
s = str(query)
if 'python' in s and 'java' in s:
print('BAD', query, articles)
complete_tag_index.assign(query, articles) complete_tag_index.assign(query, articles)
# pprint.pprint(complete_tag_index)
# complete_tag_index[query] = docs
# print(query, pool, docs)
for tag in pool: for tag in pool:
rest = pool.copy() rest = pool.copy()
rest.remove(tag) rest.remove(tag)
q = query + (tag,) q = query + (tag,)
permute(q, rest) permute(rest, q)
# RENDER FILES # RENDER FILES
################################################################################ ################################################################################
@ -447,6 +443,6 @@ ARTICLES = {
write_articles() write_articles()
complete_tag_index = Index() complete_tag_index = Index()
all_tags = set(P.get_tags()) all_tags = set(P.get_tags())
permute(tuple(), all_tags) permute(all_tags)
write_tag_pages(complete_tag_index) write_tag_pages(complete_tag_index)
write_writing_index() write_writing_index()