def __init__(self, title, url, path, url_context): self.title = title self.abs_url = url self.active = False self.url_context = url_context # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds. # See https://reproducible-builds.org/specs/source-date-epoch/ if 'SOURCE_DATE_EPOCH' in os.environ: self.update_date = datetime.datetime.utcfromtimestamp( int(os.environ['SOURCE_DATE_EPOCH']) ).strftime("%Y-%m-%d") else: self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) # Links to related pages self.previous_page = None self.next_page = None self.ancestors = [] # Placeholders to be filled in later in the build # process when we have access to the config. self.canonical_url = None self.edit_url = None self.content = None self.meta = None self.toc = None
def __init__(self, title, url, path, url_context): self.title = title self.abs_url = url self.active = False self.url_context = url_context # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds. # See https://reproducible-builds.org/specs/source-date-epoch/ if 'SOURCE_DATE_EPOCH' in os.environ: self.update_date = datetime.datetime.utcfromtimestamp( int(os.environ['SOURCE_DATE_EPOCH'])).strftime("%Y-%m-%d") else: self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) # Links to related pages self.previous_page = None self.next_page = None self.ancestors = [] # Placeholders to be filled in later in the build # process when we have access to the config. self.canonical_url = None self.edit_url = None self.content = None self.meta = None self.toc = None
def __init__(self, title, path, url_context, config): self._title = title self.classTitle = utils.get_html_title_class(title, path) self.htmlTitle = "Bmob后端云" if path.find("data/") != -1: self.htmlTitle = "数据存储 · " + self.classTitle + " – Bmob后端云" elif path.find("cloud_function/") != -1: self.htmlTitle = "云函数 · " + self.classTitle + " – Bmob后端云" elif path.find("sms/") != -1: self.htmlTitle = "短信服务 · " + self.classTitle + " – Bmob后端云" elif path.find("game/") != -1: self.htmlTitle = "游戏实时后端 · " + self.classTitle + " – Bmob后端云" elif path.find("im/") != -1: self.htmlTitle = "即时通讯 · " + self.classTitle + " – Bmob后端云" elif path.find("push/") != -1: self.htmlTitle = "推送服务 · " + self.classTitle + " – Bmob后端云" elif path.find("other/") != -1: self.htmlTitle = self.classTitle + " – Bmob后端云" self.abs_url = utils.get_url_path(path, config['use_directory_urls']) self.active = False self.url_context = url_context # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds. # See https://reproducible-builds.org/specs/source-date-epoch/ if 'SOURCE_DATE_EPOCH' in os.environ: self.update_date = datetime.datetime.utcfromtimestamp( int(os.environ['SOURCE_DATE_EPOCH'])).strftime("%Y-%m-%d") else: self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative and absolute paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) self.abs_input_path = os.path.join(config['docs_dir'], self.input_path) self.abs_output_path = os.path.join(config['site_dir'], self.output_path) self.canonical_url = None if config['site_url']: self._set_canonical_url(config['site_url']) self.edit_url = None if config['repo_url'] and config['edit_uri']: self._set_edit_url(config['repo_url'], config['edit_uri']) # Placeholders to be filled in later in the build # process when we have access to the config. self.markdown = '' self.meta = {} self.content = None self.toc = None self.previous_page = None self.next_page = None self.ancestors = []
def test_html_path(self): expected_results = { 'index.md': 'index.html', 'api-guide.md': 'api-guide/index.html', 'api-guide/index.md': 'api-guide/index.html', 'api-guide/testing.md': 'api-guide/testing/index.html', } for file_path, expected_html_path in expected_results.items(): html_path = utils.get_html_path(file_path) self.assertEqual(html_path, expected_html_path)
def __init__(self, title, url, path, url_context): self.title = title self.abs_url = url self.active = False self.url_context = url_context # Relative paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) # Links to related pages self.previous_page = None self.next_page = None self.ancestors = []
def __init__(self, title, path, url_context, config): self._title = title self.abs_url = utils.get_url_path(path, config['use_directory_urls']) self.active = False self.url_context = url_context # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds. # See https://reproducible-builds.org/specs/source-date-epoch/ if 'SOURCE_DATE_EPOCH' in os.environ: self.update_date = datetime.datetime.utcfromtimestamp( int(os.environ['SOURCE_DATE_EPOCH'])).strftime("%Y-%m-%d") else: self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative and absolute paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) self.abs_input_path = os.path.join(config['docs_dir'], self.input_path) self.abs_output_path = os.path.join(config['site_dir'], self.output_path) self.canonical_url = None if config['site_url']: self._set_canonical_url(config['site_url']) self.edit_url = None if config['repo_url']: self._set_edit_url(config['repo_url'], config['edit_uri']) # Placeholders to be filled in later in the build # process when we have access to the config. self.markdown = '' self.meta = {} self.content = None self.toc = None self.previous_page = None self.next_page = None self.ancestors = []
def __init__(self, title, path, url_context, config): self._title = title self.abs_url = utils.get_url_path(path, config['use_directory_urls']) self.active = False self.url_context = url_context # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds. # See https://reproducible-builds.org/specs/source-date-epoch/ if 'SOURCE_DATE_EPOCH' in os.environ: self.update_date = datetime.datetime.utcfromtimestamp( int(os.environ['SOURCE_DATE_EPOCH']) ).strftime("%Y-%m-%d") else: self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative and absolute paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) self.abs_input_path = os.path.join(config['docs_dir'], self.input_path) self.abs_output_path = os.path.join(config['site_dir'], self.output_path) self.canonical_url = None if config['site_url']: self._set_canonical_url(config['site_url']) self.edit_url = None if config['repo_url'] and config['edit_uri']: self._set_edit_url(config['repo_url'], config['edit_uri']) # Placeholders to be filled in later in the build # process when we have access to the config. self.markdown = '' self.meta = {} self.content = None self.toc = None self.previous_page = None self.next_page = None self.ancestors = []
def __init__(self, title, url, path, url_context): self.title = title self.abs_url = url self.active = False self.url_context = url_context self.update_date = datetime.datetime.now().strftime("%Y-%m-%d") # Relative paths to the input markdown file and output html file. self.input_path = path self.output_path = utils.get_html_path(path) # Links to related pages self.previous_page = None self.next_page = None self.ancestors = [] # Placeholders to be filled in later in the build # process when we have access to the config. self.canonical_url = None self.content = None self.meta = None self.toc = None
def build_pages(config, dump_json=False): """ Builds all the pages and writes them into the build directory. """ site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls']) loader = jinja2.FileSystemLoader(config['theme_dir']) env = jinja2.Environment(loader=loader) search_index = search.SearchIndex() build_template('404.html', env, config, site_navigation) build_template('search.html', env, config, site_navigation) nav_pages = [] for page in site_navigation.walk_pages(): nav_pages.append(page.input_path) # Read the input file input_path = os.path.join(config['docs_dir'], page.input_path) input_content = open(input_path, 'r').read() if PY2: input_content = input_content.decode('utf-8') # Process the markdown text html_content, table_of_contents, meta = convert_markdown( input_content, site_navigation, extensions=config['markdown_extensions'], strict=config['strict']) context = get_global_context(site_navigation, config) context.update( get_page_context(page, html_content, site_navigation, table_of_contents, meta, config)) # Allow 'template:' override in md source files. if 'template' in meta: template = env.get_template(meta['template'][0]) else: template = env.get_template('base.html') if not utils.is_markdown_file(page.input_path): template = env.get_template('base_without_toc.html') # Render the template. output_content = template.render(context) # Write the output file. output_path = os.path.join(config['site_dir'], page.output_path) if dump_json: json_context = { 'content': context['content'], 'title': context['current_page'].title, 'url': context['current_page'].abs_url, 'language': 'en', } utils.write_file( json.dumps(json_context, indent=4).encode('utf-8'), output_path.replace('.html', '.json')) else: utils.write_file(output_content.encode('utf-8'), output_path) search_index.add_entry_from_context(page, html_content, table_of_contents) # generate html for other md files files = ListFilesByTxt(os.path.join(config['docs_dir']), '.md') for mdf in files: title = os.path.basename(mdf) title = os.path.splitext(title)[0] path = os.path.relpath(mdf, config['docs_dir']) url = utils.get_url_path(path, config['use_directory_urls']) output_path = utils.get_html_path(path) if (path in nav_pages): continue input_content = open(mdf, 'r').read() if PY2: input_content = input_content.decode('utf-8') site_navigation.url_context.set_current_url(url) # Process the markdown text html_content, table_of_contents, meta = convert_markdown( input_content, site_navigation, extensions=config['markdown_extensions']) context = get_global_context(site_navigation, config) page = nav.Page(title=title, url=url, path=path, url_context=site_navigation.url_context) context.update( get_page_context(page, html_content, site_navigation, table_of_contents, meta, config)) if 'template' in meta: template = env.get_template(meta['template'][0]) else: template = env.get_template('base.html') if not utils.is_markdown_file(mdf): template = env.get_template('base_without_toc.html') # Render the template. output_content = template.render(context) # Write the output file. output_path = os.path.join(config['site_dir'], output_path) utils.write_file(output_content.encode('utf-8'), output_path) #search_index.add_entry_from_context(page, html_content, table_of_contents) build_template( 'js/tipuesearch/tipuesearch_content.js', env, config, extra_context={'search_index': search_index.generate_search_index()})
def build_pages(config, dump_json=False): """ Builds all the pages and writes them into the build directory. """ site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls']) loader = jinja2.FileSystemLoader(config['theme_dir']) env = jinja2.Environment(loader=loader) search_index = search.SearchIndex() build_template('404.html', env, config, site_navigation) build_template('search.html', env, config, site_navigation) nav_pages = [] for page in site_navigation.walk_pages(): nav_pages.append(page.input_path) # Read the input file input_path = os.path.join(config['docs_dir'], page.input_path) input_content = open(input_path, 'r').read() if PY2: input_content = input_content.decode('utf-8') # Process the markdown text html_content, table_of_contents, meta = convert_markdown( input_content, site_navigation, extensions=config['markdown_extensions'], strict=config['strict'] ) context = get_global_context(site_navigation, config) context.update(get_page_context( page, html_content, site_navigation, table_of_contents, meta, config )) # Allow 'template:' override in md source files. if 'template' in meta: template = env.get_template(meta['template'][0]) else: template = env.get_template('base.html') if not utils.is_markdown_file(page.input_path): template = env.get_template('base_without_toc.html') # Render the template. output_content = template.render(context) # Write the output file. output_path = os.path.join(config['site_dir'], page.output_path) if dump_json: json_context = { 'content': context['content'], 'title': context['current_page'].title, 'url': context['current_page'].abs_url, 'language': 'en', } utils.write_file(json.dumps(json_context, indent=4).encode('utf-8'), output_path.replace('.html', '.json')) else: utils.write_file(output_content.encode('utf-8'), output_path) search_index.add_entry_from_context(page, html_content, table_of_contents) # generate html for other md files files = ListFilesByTxt(os.path.join(config['docs_dir']),'.md') for mdf in files: title = os.path.basename(mdf) title = os.path.splitext(title)[0] path = os.path.relpath(mdf,config['docs_dir']) url = utils.get_url_path(path,config['use_directory_urls']) output_path = utils.get_html_path(path) if(path in nav_pages):continue input_content = open(mdf, 'r').read() if PY2: input_content = input_content.decode('utf-8') site_navigation.url_context.set_current_url(url) # Process the markdown text html_content, table_of_contents, meta = convert_markdown( input_content, site_navigation, extensions=config['markdown_extensions'] ) context = get_global_context(site_navigation, config) page = nav.Page(title=title, url=url,path=path,url_context=site_navigation.url_context) context.update(get_page_context( page, html_content, site_navigation, table_of_contents, meta, config )) if 'template' in meta: template = env.get_template(meta['template'][0]) else: template = env.get_template('base.html') if not utils.is_markdown_file(mdf): template = env.get_template('base_without_toc.html') # Render the template. output_content = template.render(context) # Write the output file. output_path = os.path.join(config['site_dir'], output_path) utils.write_file(output_content.encode('utf-8'), output_path) #search_index.add_entry_from_context(page, html_content, table_of_contents) build_template('js/tipuesearch/tipuesearch_content.js', env, config, extra_context={ 'search_index': search_index.generate_search_index() })