Skip to content

Commit

Permalink
feat: Strip out our files when generating the 'Published Documents' s…
Browse files Browse the repository at this point in the history
…ecion of a markdown index
  • Loading branch information
robtaylor committed Oct 29, 2024
1 parent 1666a1c commit b9bd116
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions doorstop/core/publishers/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def create_index(self, directory, index=INDEX, extensions=(".md",), tree=None):
"""
# Get paths for the index index
filenames = []
filenames = set()
for filename in os.listdir(directory):
if filename.endswith(extensions) and filename != INDEX:
filenames.append(os.path.join(filename))
filenames.add(os.path.join(filename))

# Create the index
if filenames:
path = os.path.join(directory, index)
log.info("creating an {}...".format(index))
lines = self.lines_index(sorted(filenames), tree=tree)
lines = self.lines_index(filenames, tree=tree)
common.write_text(" # Requirements index", path)
common.write_text("\n".join(lines), path)
else:
Expand All @@ -51,7 +51,7 @@ def create_index(self, directory, index=INDEX, extensions=(".md",), tree=None):
common.write_text(" # Source Control Status", path)
common.write_text(tree.vcs.describe(), path)

def _index_tree(self, tree, depth):
def _index_tree(self, tree, filenames, depth=0):
"""Recursively generate markdown index.
:param tree: optional tree to determine index structure
Expand All @@ -64,20 +64,22 @@ def _index_tree(self, tree, depth):
prefix = extract_prefix(tree.document)
filename = f"{prefix}.md"

filenames.remove(filename)

# Tree structure
yield " " * (depth * 2 - 1) + f"* [{prefix}]({filename}) - {title}"
# yield self.table_of_contents(linkify=True, obj=tree.document, depth=depth, heading=False)
for child in tree.children:
yield from self._index_tree(tree=child, depth=depth)

def lines_index(self, filenames, tree=None):
def lines_index(self, filenames: set, tree=None):
"""Yield lines of Markdown for index.md.
:param filenames: list of filenames to add to the index
:param tree: optional tree to determine index structure
"""
if tree:
yield from self._index_tree(tree, depth=0)
yield from self._index_tree(tree, filenames)

# Additional files
if filenames:
Expand Down

0 comments on commit b9bd116

Please sign in to comment.