我怎样才能找到鹈鹕的信号呢?我想写一个插件

2024-04-19 06:47:37 发布

您现在位置:Python中文网/ 问答频道 /正文

信号有点像是被描述的here但是,然后呢?你知道吗

例如,其中一个信号被描述为:

invoked before writing each article, the article is passed as content

如何更改该内容?如何访问它?有哪些功能?你知道吗

我一直在看github上pelican插件回购的例子,但我还是很困惑。(那些人是怎么学会写插件的?)你知道吗

我几乎不知道从哪里开始。你知道吗


Tags: the功能插件内容here信号isas
1条回答
网友
1楼 · 发布于 2024-04-19 06:47:37

你得看看pelicansource code。我想没有更好的办法了。你知道吗

例如,搜索您感兴趣的信号,例如article_generator_write_articlehttps://github.com/getpelican/pelican/search?utf8=%E2%9C%93&q=article_generator_write_article

然后,查看搜索结果,例如generators.py,并单击包含信号的行号。当然,您也可以创建一个克隆并在本地执行所有这些操作。这取决于你的工作方式。你知道吗

周围代码:

def generate_articles(self, write):
    """Generate the articles."""
    for article in chain(self.translations, self.articles):
        signals.article_generator_write_article.send(self, content=article)
        write(article.save_as, self.get_template(article.template),
              self.context, article=article, category=article.category,
              override_output=hasattr(article, 'override_save_as'), blog=True)

如您所见,signal调用为您提供了一个article对象。现在,您可以1)查看源代码以找到该对象的相应python类,以了解其内部工作方式、方法和属性,或者2)走hacky路径,只需打印对象的成员print(article.__dict__)。你知道吗

我假设,在没有查看代码的情况下,article有一个属性content,其中包含从源文件生成的HTML代码。这就是你想要改变的地方。你知道吗

请注意,如果要在处理前更改源代码,这并不是那么容易。我只是写了一点plugin,它可以做到这一点。你知道吗

在这里您还可以看到signalapi正在运行。您只需connect一个处理函数来处理所需的信号。你知道吗

我希望这有帮助:)

相关问题 更多 >