Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get current page name from path handler #2963

Closed
paternal opened this issue Feb 15, 2018 · 2 comments
Closed

Get current page name from path handler #2963

paternal opened this issue Feb 15, 2018 · 2 comments

Comments

@paternal
Copy link

paternal commented Feb 15, 2018

Environment (if reporting a bug)

Python Version: Python 3.6.4

Nikola Version: 7.8.11

Operating System: Debian testing

Description:

I am trying to write a plugin implementing a new link:// handler, and I would like it to be relative to the page it appears in (e.g. link://foo/helloworld in page bar would not return the same URL as the same link in page baz). But I cannot achieve to get the current page in the foo_path method. Is this possible?

MWE

File foo.plugin:

[Core]
Name = foo
Module = foo

File foo.py:

#!/usr/bin/env python

import os

from nikola.plugin_categories import Task
from nikola import utils

class Foo(Task):

    name = "foo"

    def set_site(self, site):
        """Set Nikola site."""
        site.register_path_handler('foo', self.foo_path)
        return super(Foo, self).set_site(site)

    def foo_path(self, name, lang):
        # Here, I would like to get the current page name/path/URL.
        return ["FOO"]

    def gen_tasks(self):
        yield self.group_task()

-- Louis

@Kwpolska
Copy link
Member

Right now, there is no support. I’m not sure if this should be supported, since the existing path handlers are independent of the environment they’re in (except for language). What page-specific thing would be done in your links?

@paternal
Copy link
Author

What page-specific thing would be done in your links?

When trying to put data in the same directories as pages (as discussed in #2266), I tried to make a attachment page handler, where link link://attachment/data.tar in page pages/foo.rst would return a link to pages/foo/data.tar.
A less specific answer is: I was trying to make link:// return relative links.

But (again, as discussed in #2266), it seems that I eventually do not need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants