apenwarr / mkdocs-exclude

A mkdocs plugin that lets you exclude files or trees from your output.
Apache License 2.0
86 stars 10 forks source link

Possible to include only some files? #3

Open feustpat opened 5 years ago

feustpat commented 5 years ago

I have a quite large page tree but only want to include a couple of md-Files. Is it possible to invert the patterns, i.E. only include some specific files and exclude everything else?

oxr463 commented 4 years ago

If that is the case, simply specify those files explicitly in the nav: section of your mkdocs.yml file.

majkinetor commented 4 years ago

That is not the same as mkdocs will build hidden files and those can be accessed with URL.

Better option is to support negative look behind. This doesn't seem to work currently.

Example

I keep functional spec, technical docs and user manual in the same mkdocs project. So my nav sections contains something like:

...
nav: 
- Functional spec:      #in folder funspec
...
- Tehcnical docs        #in folder techdoc
...
- User manual           #in folder user
...

On specific environment, I might want to deploy full docs or only specific sections, such as user manual. I have a script that removes unwanted sections from the nav and produces new config file. I don't want to remove unwanted files before build since that is destructive operation so I thought this will work if I want only user documentation

regex: ['(?<!user)/.+']

Currently I have to use this:

regex: ['(funspec|tech)/.+']

which is not ideal as I need to parse mkdocs config to find out all available sections.

This would exactly do what OP wanted with custom config file as you suggested.

wilhelmer commented 4 years ago

Negative look~behind~ahead works for me. This excludes everything except topics "topic1.md" and "index.md":

regex:
     - '^((?!topic1|index).)*\.md$'

This is also super handy in large projects, when building the entire projects takes 4-5 minutes, but you only want to check changes on a single topic.

majkinetor commented 4 years ago

That is negative lookahead

wilhelmer commented 4 years ago

Oh true, edited 😄

balrok commented 3 years ago

I also needed this feature, but I just wanted to include every .md and nothing else:

regex:
    - '.*(?<!(md|MD))$'

This works right now, but if I later need to include .jpg it will not work out since all look-behind patterns need to be fixed width. Having a second regex will not work. Since they would both cancel each other out.

I think having something like include-regex and include-glob would be great.. and later maybe also an option to set if exclude or include should have the highest priority

wilhelmer commented 3 years ago

This works right now, but if I later need to include .jpg it will not work out since all look-behind patterns need to be fixed width.

Can't you extend the include list like this?

regex:
    - '.*(?<!(md|MD|jpg|JPG))$'
balrok commented 3 years ago

Maybe when rewriting it to a look-ahead its possible? But a look-behind has to be fixed-width. Additionally, I wanted to use the material theme and so have to include *.md and assets/* - this is probably not possible anymore. And lastly, I think its really cumbersome to write it down like this and nobody in my team would like to touch this.

DariuszPorowski commented 1 year ago

@feustpat @majkinetor I had similar case. Tried to use mkdocs-exclude plugin but it does not meet my requirements and unfortunately, it looks like it's not maintained anymore. I developed a plugin for includes/excludes that supports external config with rules based on env var and navigation filtering based on excludes.

You can find it here: https://github.com/DariuszPorowski/mkdocs-file-filter-plugin

It works for me, and I am happy to get feedback, ideas, improvements, etc.