2024-04-19 06:47:37 发布
网友
信号有点像是被描述的here但是,然后呢?你知道吗
例如,其中一个信号被描述为:
invoked before writing each article, the article is passed as content
如何更改该内容?如何访问它?有哪些功能?你知道吗
我一直在看github上pelican插件回购的例子,但我还是很困惑。(那些人是怎么学会写插件的?)你知道吗
我几乎不知道从哪里开始。你知道吗
你得看看pelican的source code。我想没有更好的办法了。你知道吗
pelican
例如,搜索您感兴趣的信号,例如article_generator_write_article:https://github.com/getpelican/pelican/search?utf8=%E2%9C%93&q=article_generator_write_article
article_generator_write_article
然后,查看搜索结果,例如generators.py,并单击包含信号的行号。当然,您也可以创建一个克隆并在本地执行所有这些操作。这取决于你的工作方式。你知道吗
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
print(article.__dict__)
我假设,在没有查看代码的情况下,article有一个属性content,其中包含从源文件生成的HTML代码。这就是你想要改变的地方。你知道吗
content
请注意,如果要在处理前更改源代码,这并不是那么容易。我只是写了一点plugin,它可以做到这一点。你知道吗
在这里您还可以看到signalapi正在运行。您只需connect一个处理函数来处理所需的信号。你知道吗
connect
我希望这有帮助:)
你得看看
pelican
的source code。我想没有更好的办法了。你知道吗例如,搜索您感兴趣的信号,例如
article_generator_write_article
:https://github.com/getpelican/pelican/search?utf8=%E2%9C%93&q=article_generator_write_article然后,查看搜索结果,例如
generators.py
,并单击包含信号的行号。当然,您也可以创建一个克隆并在本地执行所有这些操作。这取决于你的工作方式。你知道吗周围代码:
如您所见,signal调用为您提供了一个
article
对象。现在,您可以1)查看源代码以找到该对象的相应python类,以了解其内部工作方式、方法和属性,或者2)走hacky路径,只需打印对象的成员print(article.__dict__)
。你知道吗我假设,在没有查看代码的情况下,
article
有一个属性content
,其中包含从源文件生成的HTML代码。这就是你想要改变的地方。你知道吗请注意,如果要在处理前更改源代码,这并不是那么容易。我只是写了一点plugin,它可以做到这一点。你知道吗
在这里您还可以看到signalapi正在运行。您只需
connect
一个处理函数来处理所需的信号。你知道吗我希望这有帮助:)
相关问题 更多 >
编程相关推荐