示例#1
0
    def on_page_markdown(
        self,
        markdown: str,
        page: Page,
        config: Config,
        files: Files,
    ):
        """Inject page template path, if necessary."""
        page.iri = iri_by_page(page)

        try:
            template_url = Render(
                ldflex=self.octiron.ldflex,
            ).find_facet_iri(
                node=page.iri,
                environments=[URIRef(OCTA)],
            )
        except FacetNotFound:
            return markdown

        page.meta['template'] = re.sub(
            '^templates:',
            '',
            template_url,
        )

        return markdown
示例#2
0
    def on_page_context(
        self,
        context: TemplateContext,
        page: Page,
        config: Config,
        nav: Page,
    ) -> TemplateContext:
        """Attach the views to certain pages."""
        page_iri = rdflib.URIRef(
            f'{LOCAL}{page.file.src_path}',
        )

        this_choices = list(map(
            operator.itemgetter(rdflib.Variable('this')),
            self.octiron.graph.query(
                'SELECT * WHERE { ?this octa:subjectOf ?page_iri }',
                initBindings={
                    'page_iri': page_iri,
                },
            ).bindings,
        ))

        if this_choices:
            context['this'] = this_choices[0]
        else:
            context['this'] = page_iri

        context['graph'] = self.octiron.graph
        context['iri'] = page_iri

        # noinspection PyTypedDict
        context['query'] = partial(
            query,
            instance=self.octiron.graph,
        )
        context['queries'] = self.stored_query

        context['local'] = LOCAL
        context['LOCAL'] = LOCAL
        context.update(self.octiron.namespaces)

        context['render'] = partial(
            render,
            octiron=self.octiron,
        )

        # Provide all the support namespaces into template context
        context['octiron'] = self.octiron
        context['link'] = partial(
            link,
            octiron=self.octiron,
        )

        # Page attributes
        page.iri = page_iri

        return context