Skip to content

Commit

Permalink
Use document title as isso thread title
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Apr 21, 2021
1 parent 1abf713 commit 2a74644
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions sphinxnotes/isso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from sphinx.application import Sphinx
from sphinx.util import logging

__title__= 'sphinxnotes-isso'
__license__ = 'BSD',
Expand All @@ -36,6 +37,8 @@
'isso_avatar_fg', 'isso_vote', 'isso_vote_levels',
'isso_feed']

logger = logging.getLogger(__name__)

def ext_config_to_isso_config(key:str, value:Any) -> Tuple[str,str]:
assert key in CONFIG_ITEMS
key = 'data-' + key.replace('_', '-')
Expand All @@ -55,8 +58,11 @@ def visit(self, node):
kwargs = {
'data-isso-id': node['thread-id'],
}
if node.get('thread-title'):
kwargs['data-title'] = node['thread-title']
self.body.append(self.starttag(node, 'section', '', **kwargs))


@staticmethod
def depart(self, _):
self.body.append('</section>')
Expand All @@ -66,7 +72,8 @@ class IssoDirective(Directive):
"""Isso ".. isso::" rst directive."""

option_spec = {
'id': directives.unchanged
'id': directives.unchanged,
'title': directives.unchanged,
}

def run(self):
Expand All @@ -77,11 +84,23 @@ def run(self):

node = IssoNode()
node['ids'] = ['isso-thread']
node['thread-id'] = self.options.get('id') or \
'/' + self.state.document.settings.env.docname
if self.options.get('id'):
thread_id = self.options.get('id')
if not thread_id.startswith('/'):
logger.warning('isso thread-id should starts with slash', location=node)
node['thread-id'] = thread_id
else:
node['thread-id'] = '/' + self.state.document.settings.env.docname
if self.options.get('title'):
node['thread-title'] = self.options.get('title')
else:
title = self.state.document.next_node(nodes.title)
if title:
node['thread-title'] = title.astext()

return [node]


def on_html_page_context(app:Sphinx, pagename:str, templatename:str, context,
doctree:nodes.document) -> None:
"""Called when the HTML builder has created a context dictionary to render a template with.
Expand Down

0 comments on commit 2a74644

Please sign in to comment.