alanpt / mkdocs-pagelist-plugin

Create list of pages that use a particular tag, grouped by folder.
1 stars 1 forks source link

FEATURE REQUEST: logical operators when specifying tags and exclude myself #2

Open pitrson opened 3 months ago

pitrson commented 3 months ago

Hello there,

first of all - many thanks for your work! Your plugin is really amazing and it is the only one available which was (almost) able to fulfill my needs :-). Now when it comes to my feature request I'm missing few important (IMHO) functionalities:

Exclude myself from the generated links

Add logical operators for tags in pagelist

Current state: { pagelist 100 tag1 tag2}

My idea would be something like this:

Many thanks again! Let me please know if any help or testing is needed.

Cheers

alanpt commented 3 months ago

Hi Pitrson!

That first point was a problem for me too the other day.

The second one how about this:

{pagelist tag1 tag2} for any pages with either of those tags (Current) {pagelist tag1 -tag2} for pages with tag1 but not if it also is tagged with tag2 (Current) `{pagelist +tag1 +tag2} for pages tagged with both those tags (New)

Thanks for the offer of help. I don't have the time right now to do these changes unfortunatly. Maybe in a few weeks?

pitrson commented 1 month ago

Hi @alanpt

I was checking the code today and I've seen that the '+tag' is already implemented.

        any_tags = {tag for tag in tags_to_filter if not tag.startswith('+') and not tag.startswith('-')}
        all_tags = {tag.lstrip('+') for tag in tags_to_filter if tag.startswith('+')}
        exclude_tags = {tag.lstrip('-') for tag in tags_to_filter if tag.startswith('-')}

        any_match = any(tag in page_tags for tag in any_tags) if any_tags else True
        all_match = all(tag in page_tags for tag in all_tags)
        exclude_match = not any(tag in page_tags for tag in exclude_tags)

        return any_match and all_match and exclude_match

It works sufficiently for my needs (for now ^^). I will submit a PR which reflects this in the README and makes sure that it doesn't generate link for "myself" and include few minor fixes I came across.