Comments (8)
A plugin, if it really wanted to, can already use the unwatch
function on the main directory.
I don't think this should be generally supported though.
There should be no need to physically copy files. #3451 will make it easier to express adding external files in terms of the File
API, and later this could be taken further - to make it easier to include whole directories and possibly not require writing any code.
from mkdocs.
Before opening a PR, please wait a bit for other maintainers opinion π
I'll tag some of them in case they'd like to chime in: @oprypin @ultrabug
from mkdocs.
Great, so we can simply hook into on_serve
(in a plugin or a simple hook) and use server.unwatch("path/to/directory")
. Since there's an easy hook-based solution for this, and future changes that can make this even easier, I'll close this issue. Thanks @oprypin!
from mkdocs.
here should be no need to physically copy files. #3451 will make it easier to express adding external files in terms of the File API, and later this could be taken further - to make it easier to include whole directories and possibly not require writing any code.
That looks great, thanks for sharing. I'll consider using the File api in the future.
Great, so we can simply hook into on_serve (in a plugin or a simple hook) and use server.unwatch("path/to/directory")
That worked well for me. Thanks for the additional links, they were very helpful.
from mkdocs.
Hello!
Does this temp dir being watched cause you issues? Which ones?
How do you aggregate files? With a custom script before using MkDocs, or with a plugin hook?
from mkdocs.
Does this temp dir being watched cause you issues? Which ones?
How do you aggregate files? With a custom script before using MkDocs, or with a plugin hook?
The tempdir being watched causes an infinite reload problem. I set the real docs-source to be watched and, when something changes there, a plugin hook (I actually use mkdocs_macro hooks) copies that to the tempdir, which is also being watched
It's not obvious why this recurses (I think it should stop reloading after the second trigger) and maybe I can find a way of preventing that in my code, but that simply doesn't happen if I disable watching tempdir in the first place.
from mkdocs.
Yes I see what you mean. So, if I understand correctly, you add source directories to the watch list, and it lets you copy all relevant files from these folders (thanks to some mkdocs-macros magic) into a final but temporary docs directory, from which the site is built. Since this temporary docs directory is the one assigned to docs_dir
, it's automatically added to the watch list. But changes only occur in this directory when they first occur in the real source ones, so it doesn't make sense to watch it.
So, the feature makes sense to me (having more control over what is watched) and would surely help other users (this is not the first time someone experiences that). But let me try to describe an alternative first. I don't want to convince you it is a better alternative, I just want to lay it out here for future reference and completeness π
There is a way to add files to the source docs directory without triggering a reload. MkDocs API allows to add files without actually copying them to the docs source folder. That's what the mkdocs-gen-files plugin does: it creates files in a temporary directory (not in the docs sources), and uses MkDocs' API to "register" these files as if they were in the docs sources. I believe it is possible to use a similar approach for your use-case, or maybe even use mkdocs-gen-files directly.
Let say you have a list of source folders: ["/path/to/source1", "/path/to/source2"]
. You want to copy all files within these sources into the final docs directory docs
. You'd configure mkdocs-gen-files like this:
plugins:
- gen-files:
scripts:
- copy_sources.py
And you would write the copy_sources.py
script like this:
from pathlib import Path
import mkdocs_gen_files
sources = [Path("/path/to/source1"), Path("/path/to/source2")]
def recursive_copy(source: Path, directory: Path):
for each in directory.iterdir():
if each.is_dir():
recursive_copy(source, each)
else:
with mkdocs_gen_files.open(each.relative_to(source), "wb") as file:
file.write(each.read_bytes())
for source in sources:
recursive_copy(source, source)
(not tested, but it shouldn't be far from working π)
With this, each build would "replicate" all the files and folders from your real sources into the final docs
directory, without triggering reload when there are changes in docs
(unless you actually write into it through other means).
from mkdocs.
Thanks for pointing out this alternative, I might give it a try.
And since the feature seems to make sense, I should open a PR shortly.
from mkdocs.
Related Issues (20)
- Uncaught DOMException: Element.querySelectorAll: '> .dropdown-submenu > a' is not a valid selector HOT 5
- Substring search does not work
- Improve performance and authoring experience of `mkdocs serve` HOT 14
- Emit INFO instead of WARNING for Deprecated options HOT 5
- Break search plugin out into separate package HOT 8
- Empty mkdocs_theme.yml breaks build
- Generate nav with links to headers HOT 1
- ModuleNotFoundError: No module named 'mkdocs.tests' HOT 1
- FR: Anchor validation warning should remind the user it's case sensitive, especially if there are case-insensitive matches. HOT 3
- Anchor validation and special characters. HOT 2
- How to specify the port in MkDocs HOT 1
- AttributeError: 'EntryPoints' object has no attribute 'get' in xarray.backends HOT 1
- Should the markdown renderer treat a single line break as <br>? HOT 2
- Feature Request: Extend the `on_page_context` event with the reference to the Jinja2 Environment HOT 1
- Mkdocs no longer respecting set display text for same .md files. HOT 3
- Cannot get mkdocs to recognize the caseinsensitive plugin HOT 1
- Table display βflickersβ when refreshing the page HOT 2
- sourcing an external js library with in mkdocs HOT 6
- Please allow running MkDocs with Docker and strict mode HOT 6
- Default theme: N and P keys no longer work HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mkdocs.