def apply_rules(self, chapters): """HEpigram-specific rules that must be applied to the given HEpigram.yml and then passed to MkDocs""" # Rule 1 - If first chapter is a single entry, rename it to index. first_page_key = list(chapters[0].keys())[0] first_page = chapters[0][first_page_key] # First chapter is not a single page, so no index for you. if not isinstance(first_page, str): return chapters # We already have an index (: if first_page == 'index': return chapters # Change `first_page.md` to `index.md` on our build dir cmd = 'mv {build}/{fp} {build}/index.md'.format( build=self.MkDocs.BUILD_DIR, fp=first_page ).replace('//', '/') call(cmd, shell=True) # Change `first_page.md` to `index.md` on our chapters list. chapters[0][first_page_key] = 'index.md' return chapters
def clone(self, destination): print('Cloning into', destination) cmd = 'git clone {origin} {destination} > /dev/null 2>&1'.format( origin=self.ORIGIN_PATH, destination=destination ) call(cmd, shell=True)
def create_build_env(self): # Create the build dir, if it doesnt exists. os.makedirs(self.BUILD_DIR, exist_ok=True) # Copy theme to build location # Copy source files to build dir. if self.DOCS_DIR != self.BUILD_DIR: cmd = 'cp -r {source}/* {build} >> /dev/null'.format( source=self.DOCS_DIR, build=self.BUILD_DIR ).replace('//*', '/*') call(cmd, shell=True)
def serve(self): cmd = 'mkdocs serve -f {config} --livereload'.format( config=self.config_file(), ).split(' ') call(cmd)
def build(self): cmd = 'mkdocs build -f {config} -d {output} --clean'.format( config=self.config_file(), output=self.OUTPUT_DIR ).split(' ') call(cmd)