예제 #1
0
파일: pages.py 프로젝트: zeineb/mkdocs
    def _set_title(self):
        """
        Set the title for a Markdown document.

        Check these in order and use the first that returns a valid title:
        - value provided on init (passed in from config)
        - value of metadata 'title'
        - content of the first H1 in Markdown content
        - convert filename to title
        """
        if self.title is not None:
            return

        if 'title' in self.meta:
            self.title = self.meta['title']
            return

        title = get_markdown_title(self.markdown)

        if title is None:
            if self.is_homepage:
                title = 'Home'
            else:
                title = self.file.name.replace('-', ' ').replace('_', ' ')
                # Capitalize if the filename was all lowercase, otherwise leave it as-is.
                if title.lower() == title:
                    title = title.capitalize()

        self.title = title
예제 #2
0
                def navFromDir(path):
                    directory = {}

                    for dirname, dirnames, filenames in os.walk(path):

                        dirnames.sort()
                        filenames.sort()

                        if dirname == docsDirPath:
                            dn = os.path.basename(dirname)
                        else:
                            dn = dirname_to_title(os.path.basename(dirname))
                        directory[dn] = []

                        for dirItem in dirnames:
                            subNav = navFromDir(
                                path=os.path.join(path, dirItem))
                            if subNav:
                                directory[dn].append(subNav)

                        for fileItem in filenames:
                            fileName, fileExt = os.path.splitext(fileItem)
                            if fileExt == '.md':
                                fileTitle = get_markdown_title(fileName)
                                filePath = os.path.join(
                                    os.path.relpath(path, docsDirPath),
                                    fileItem)
                                directory[dn].append({fileTitle: filePath})

                        if len(directory[dn]) == 0 or directory[dn] == [{}]:
                            del directory[dn]

                        return directory
예제 #3
0
파일: pages.py 프로젝트: mkdocs/mkdocs
    def _set_title(self):
        """
        Set the title for a Markdown document.

        Check these in order and use the first that returns a valid title:
        - value provided on init (passed in from config)
        - value of metadata 'title'
        - content of the first H1 in Markdown content
        - convert filename to title
        """
        if self.title is not None:
            return

        if 'title' in self.meta:
            self.title = self.meta['title']
            return

        title = get_markdown_title(self.markdown)

        if title is None:
            if self.is_homepage:
                title = 'Home'
            else:
                title = self.file.name.replace('-', ' ').replace('_', ' ')
                # Capitalize if the filename was all lowercase, otherwise leave it as-is.
                if title.lower() == title:
                    title = title.capitalize()

        self.title = title
예제 #4
0
    def title(self):
        """
        Get the title for a Markdown document
        Check these in order and return the first that has a valid title:
        - self._title which is populated from the mkdocs.yml
        - self.meta['title'] which comes from the page metadata
        - self.markdown - look for the first H1
        - self.input_path - create a title based on the filename
        """
        if self._title is not None:
            return self._title
        elif 'title' in self.meta:
            return self.meta['title']

        title = utils.get_markdown_title(self.markdown)

        if title is not None:
            return title

        return _filename_to_title(self.input_path.split(os.path.sep)[-1])
예제 #5
0
파일: nav.py 프로젝트: jimporter/mkdocs
    def title(self):
        """
        Get the title for a Markdown document
        Check these in order and return the first that has a valid title:
        - self._title which is populated from the mkdocs.yml
        - self.meta['title'] which comes from the page metadata
        - self.markdown - look for the first H1
        - self.input_path - create a title based on the filename
        """
        if self._title is not None:
            return self._title
        elif 'title' in self.meta:
            return self.meta['title']

        title = utils.get_markdown_title(self.markdown)

        if title is not None:
            return title

        return _filename_to_title(self.input_path.split(os.path.sep)[-1])