Skip to content

Internal refactoring. - #689

Closed
lovelydinosaur wants to merge 9 commits into
masterfrom
restructure-compat
Closed

lovelydinosaur wants to merge 9 commits into
masterfrom
restructure-compat

Conversation

@lovelydinosaur

Copy link
Copy Markdown
Collaborator

Builds site in memory.

Presents a clean internal API, that is more comprehensible, allows us to make improvements more easily, and paves path to fully documented build behaviors and context available to themes.

In broader context this is a big step towards #683, but at this point I just want to present a fully compatible internal refactoring that should allow us to sort out a bunch of issues.

TODO:

  • Set page.url and nav.is_active states on each page.
  • Build 404.html, search and other template pages.
  • Support multiple theme directories, as per current build style.
  • Support use_directory_urls.
  • Support extra_css, extra_javascript, extra_templates.
  • Review relative url's can cause bad links #77, particularly search URLs, and anywhere abs_url is used.
  • Warn on duplicate output files in build.
  • print statements -> warn/error.
  • Tests, tests, tests.
  • Cleanup unused bits in utils.
  • Verify identical site build before/after this change.
  • Document internal structure.
  • Build but warn on .md files not in pages.
  • Ensure markdown extensions in config are supported.
  • OrderedDict for yaml loading of config.

Resolves:
#653 - Relative paths to media sometimes broken.
#316 - Determine default titles from page table of contents.
#192 - Allow absolute URL links in source pages.
#608 - Allow README.md or others as homepage.

Makes these viable:
#658 - Validate links to anchors.
#167 - Only warn on properly stale files in site dir.
#699 - Build all markdown files.

No ticket - Support HTML files in nav.
No ticket - Support alternate layout eg /path/to/file.html vs path/to/file/index.html.

@lovelydinosaur lovelydinosaur added this to the 0.15.0 milestone Jul 10, 2015
Comment thread mkdocs/structure/files.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated in the urls.py, would it be better to expand/change the is_markdown utility method and use that? or maybe just have a set of constants somewhere for these lists.

@d0ugal

d0ugal commented Jul 12, 2015

Copy link
Copy Markdown
Contributor

Looks like a good start, but obviosuly still tons to do. So I just gave it a quick once over. My primary concern with wide sweeping refactors like this is what we might break. I tend to do these things in much smaller steps.

@lovelydinosaur

Copy link
Copy Markdown
Collaborator Author

I tend to do these things in much smaller steps.

Likewise. Clearly breaking the rules here.

@lovelydinosaur

Copy link
Copy Markdown
Collaborator Author

I tend to do these things in much smaller steps.

Likewise. Clearly breaking all the rules here.

@d0ugal

d0ugal commented Jul 14, 2015

Copy link
Copy Markdown
Contributor

I tend to do these things in much smaller steps.

Likewise. Clearly breaking all the rules here.

Maybe we can treat this branch as an incubator and slowly move changes into master? Trying to think of a decent workflow. Next week I hope to have time for MkDocs as I'll be at EuroPython and plan on sprinting. However, it will be tricky to do much without conflicting badly with this work and I don't want to cause you a massive headache. I'd be happy to help drive this forward too, but not sure I can easily do that yet.

Open to ideas.

@waylan waylan mentioned this pull request Jul 29, 2015
@d0ugal

d0ugal commented Aug 3, 2015

Copy link
Copy Markdown
Contributor

How can I help push this work forward?

@lovelydinosaur

Copy link
Copy Markdown
Collaborator Author

@d0ugal Possibilities:

  • There's some items on the checklist above that'd be obviously actionable. Eg print statements -> logging.
  • There's some items on the checklist that I could take you through if you wanted to take them on.

Alternatively

  • Taking a more radical tack on what we're expecting from 1.0 (eg. not necessarily 100% compatible against custom theme templates) would allow us to treat this work as a cleaner slate, and not get too bogged down in figuring out the gradual migration approach.

@d0ugal

d0ugal commented Aug 4, 2015

Copy link
Copy Markdown
Contributor
  • Taking a more radical tack on what we're expecting from 1.0 (eg. not necessarily 100% compatible against custom theme templates) would allow us to treat this work as a cleaner slate, and not get too bogged down in figuring out the gradual migration approach.

If we call the next release 1.0, then I am happy to break things so long as we provide users with clear docs to upgrade. I wouldn't be happy about a 0.15.0 release breaking all the things.

I can try and look at some of the check list items - I guess I'll send a pull request against this branch if I get something together.

@lovelydinosaur

Copy link
Copy Markdown
Collaborator Author

If we call the next release 1.0, then I am happy to break things so long as we provide users with clear docs to upgrade. I wouldn't be happy about a 0.15.0 release breaking all the things.

My preference would be to work on a 1.0 release that provides an easy upgrade path for users of the existing themes. - I can make a pull request that doesn't respect all the backwards compat of this one for us to consider working on.

@d0ugal

d0ugal commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

I think this work is really valuable, and needs to happen at some point - but to tidy up a bit I'll close this as it has fallen out of date. Happy for a new PR to be opened.

@d0ugal d0ugal closed this Mar 8, 2016
@d0ugal
d0ugal deleted the restructure-compat branch May 31, 2016 10:14
waylan pushed a commit to waylan/mkdocs that referenced this pull request May 18, 2017
This is only the contents of the 'structure' dir from mkdocs#689.
Still needs to be implemented in the build process after being updated.
waylan pushed a commit to waylan/mkdocs that referenced this pull request May 18, 2017
This is only the contents of the 'structure' dir from mkdocs#689.
Still needs to be implemented in the build process after being updated.
waylan pushed a commit to waylan/mkdocs that referenced this pull request Nov 2, 2017
This is only the contents of the 'structure' dir from mkdocs#689.
Still needs to be implemented in the build process after being updated.
waylan pushed a commit to waylan/mkdocs that referenced this pull request Apr 17, 2018
This is only the contents of the 'structure' dir from mkdocs#689.
Still needs to be implemented in the build process after being updated.
waylan pushed a commit to waylan/mkdocs that referenced this pull request May 9, 2018
This is only the contents of the 'structure' dir from mkdocs#689.
Still needs to be implemented in the build process after being updated.
@waylan waylan mentioned this pull request Jun 8, 2018
waylan added a commit that referenced this pull request Jun 28, 2018
Internal handling of pages, files and navigation has been completely refactored.
The changes included in the refactor are summarized below.

* Support for hidden pages. All Markdown pages are now included in the build
  regardless of whether they are included in the navigation configuration
  (fixes #699).
* The navigation can now include links to external sites (fixes #989, fixes #1373,
  & fixes #1406).
* Page data (including titles) is properly determined for all pages before any
  page is rendered (fixes #1347).
* Automatically populated navigation now sorts index pages to the top. In other
  words, The index page will be listed as the first child of a directory, while
  all other documents are sorted alphanumerically by file name after the index
  page (fixes #73 & fixes #1042).
* A `README.md` file is now treated as an index file within a directory and
  will be rendered to `index.html` (fixes #608).
* The URLs for all files are computed once and stored in a files collection.
  This ensures all internal links are always computed correctly regardless of
  the configuration. This also allows all internal links to be validated, not
  just links to other Markdown pages. (fixes #842 & fixes #872).
* An `on_files` plugin event has been added, which could be used to include
  files not in the `docs_dir`, exclude files, redefine page URLs (i.e.
  implement extensionless URLs), or to manipulate files in various other ways.

Backward incompatible changes are highlighted in the release notes included 
with this commit. Some notes regarding various decisions follow in no particular 
order:

This started out as the contents of the 'structure' dir from @tomchristie's 
work in #689.

All paths must be all Unicode all the time. When a byte string and a 
Unicode string are both passed to os.path (join ect) then returned value 
is always a byte string. Therefore, we need every path string to be 
Unicode. This ensures validation checks that and if the byte string uses 
the file system encoding, decodes it. For any other encoding, a 
validation error is raised.

Paths which start with a slash are assumed to be relative to the
docs_dir root. This behavior fixes #192. However, the slash not being
present in the output may surprise some users who are trying to create a
link relative to the server root when the mkdocs root is not at the
server root. The URLs available on a page are:

* Page.url is the url relative to the site_dir
* Page.canonical_url is the relative url joined with site_url or None if
  site_url is not defined (the default).
* Page.abs_url is the path component of the canonical url or None if
  canonical_url is None.

Note that new behavior is slightly different than before. Previously
abs_url ignored site_url and was always url with '' prepended. With the
new behavior, if site_url includes a subdir, that subdir will be
included in the abs_url.

When not on a server, there is no sensable "absolute_url" for a page.
Therefore, we shouldn't try to define one.

The thinking is that users generating docs to be browsed in the local
file system (`file://`) should leave the site_url setting unset, while
users who will be serving their docs from a server should be setting the
site_url. And if the site_url point sot a subdir of the server, the
abs_url will stil be absolute from the server root as it uses the "path"
of the canonical_url of the page.

Note that without the magical url context all URLs must be prepended by
`{{ base_url }}/` in the templates. While this requires a change in
third party themes, it is more consistent.

Links being ignored in raw HTML is now documented. Fixes #991.

All related tests that require temp dirs use the `mkdocs.tests.base.tempdir`
decorator. Note that any unrelated tests have not yet been updated. 
That can happen separately from this. The one test in 
`mkdocs.tests.structure.page_tests` (test_BOM) is unique enough to 
not use the decorator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants