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

Raw copy files with invalid extensions. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/markdoc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def crumbs(self, path):
crumbs.append((terminus, None))
return crumbs

def valid_extension(self, filename):
return any(filename.endswith(valid_ext)
for valid_ext in self.config['document-extensions'])

def walk(self):

"""
Expand All @@ -86,15 +90,11 @@ def walk(self):
if not self.config['document-extensions']:
self.config['document-extensions'].append('')

def valid_extension(filename):
return any(filename.endswith(valid_ext)
for valid_ext in self.config['document-extensions'])

for dirpath, subdirs, files in os.walk(self.config.wiki_dir):
remove_hidden(subdirs); subdirs.sort()
remove_hidden(files); files.sort()

for filename in filter(valid_extension, files):
for filename in files:
full_filename = p.join(dirpath, filename)
yield p.relpath(full_filename, start=self.config.wiki_dir)

Expand Down
26 changes: 18 additions & 8 deletions src/markdoc/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,30 @@ def build(config, args):

builder = Builder(config)
for rel_filename in builder.walk():
html = builder.render_document(rel_filename)
out_filename = p.join(config.temp_dir,
p.splitext(rel_filename)[0] + p.extsep + 'html')
is_source = builder.valid_extension(rel_filename)

if is_source:
out_filename = p.join(config.temp_dir,
p.splitext(rel_filename)[0] + p.extsep + 'html')
else:
out_filename = p.join(config.temp_dir, rel_filename)

if not p.exists(p.dirname(out_filename)):
log.debug('makedirs %s' % p.dirname(out_filename))
os.makedirs(p.dirname(out_filename))

log.debug('Creating %s' % p.relpath(out_filename, start=config.temp_dir))
fp = codecs.open(out_filename, 'w', encoding='utf-8')
try:
fp.write(html)
finally:
fp.close()

if is_source:
html = builder.render_document(rel_filename)
fp = codecs.open(out_filename, 'w', encoding='utf-8')
try:
fp.write(html)
finally:
fp.close()
else:
in_filename = p.join(config.wiki_dir, rel_filename)
shutil.copyfile(in_filename, out_filename)

sync_html(config, args)
build_listing(config, args)
Expand Down