This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
Fix "error: Document is empty." when empty files are present in /docs #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Symptom
When combined with mkdocs-video, an ERROR will occur if there are empty md files in the
/docs
path.mkdocs-video/mkdocs_video/plugin.py
Lines 27 to 34 in 4c9b1fb
Analysis
According to the error message, I took a look at the code on line 761 of file
lxml\html\__init__.py
:at https://github.com/lxml/lxml/blob/762f62c5a1ab62ce37397aeeab2c27fdcc14ca66/src/lxml/html/__init__.py#L756-L767
My understanding is that as
mkdocs-video
useslxml
, and whenlxml
converts the Markdown files, an ERROR is thrown because one of the Markdown files is empty and hencevalue is None
.As long as there are empty files present in
/docs
, an ERROR will be reported, even if thenav
setting inmkdocs.yml
did not explicitly include the file as a page.Fix
In an attempt to fix this (rather easily), an extra check is added to the
on_page_content
method. The method will execute only when the passedhtml
object is not empty, effectively skipping the empty file (as we don't need to process it anyways).In hindsight, I think
mkdocs
does allow empty files to exist in/docs
(site builds will proceed without problems with empty files). Withmkdocs-video
, site builds will fail with the symptom described above. With this patch, site builds will succeed without problems, just like before. The fix may not be perfect and may need some further modifications to meet project standards.