Skip to content

Commit bb50bff

Browse files
authored
[FEATURE] Connection to talk.typo3.org (#950)
1 parent 80fa154 commit bb50bff

File tree

9 files changed

+233
-1
lines changed

9 files changed

+233
-1
lines changed

packages/typo3-docs-theme/resources/config/typo3-docs-theme.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\RedirectsNodeTransformer;
2626
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\RemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer;
2727
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\ReplacePermalinksNodeTransformer;
28+
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\Typo3TalkNodeTransformer;
2829
use T3Docs\Typo3DocsTheme\Directives\ConfvalMenuDirective;
2930
use T3Docs\Typo3DocsTheme\Directives\DirectoryTreeDirective;
3031
use T3Docs\Typo3DocsTheme\Directives\GlossaryDirective;
@@ -36,6 +37,7 @@
3637
use T3Docs\Typo3DocsTheme\Directives\SiteSetSettingsDirective;
3738
use T3Docs\Typo3DocsTheme\Directives\T3FieldListTableDirective;
3839
use T3Docs\Typo3DocsTheme\Directives\Typo3FileDirective;
40+
use T3Docs\Typo3DocsTheme\Directives\Typo3TalkDirective;
3941
use T3Docs\Typo3DocsTheme\Directives\ViewHelperDirective;
4042
use T3Docs\Typo3DocsTheme\Directives\YoutubeDirective;
4143
use T3Docs\Typo3DocsTheme\EventListeners\AddThemeSettingsToProjectNode;
@@ -105,7 +107,8 @@
105107
->tag('phpdoc.guides.compiler.nodeTransformers')
106108
->set(RemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer::class)
107109
->tag('phpdoc.guides.compiler.nodeTransformers')
108-
->set(TwigExtension::class)
110+
->set(Typo3TalkNodeTransformer::class)
111+
->tag('phpdoc.guides.compiler.nodeTransformers')
109112
->set(TwigExtension::class)
110113
->tag('twig.extension')
111114
->autowire()
@@ -192,6 +195,7 @@
192195
->set(SiteSetSettingsDirective::class)
193196
->set(Typo3FileDirective::class)
194197
->set(T3FieldListTableDirective::class)
198+
->set(Typo3TalkDirective::class)
195199
->set(ViewHelperDirective::class)
196200
->arg('$startingRule', service(DocumentRule::class))
197201
->set(YoutubeDirective::class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% if node.sectionNode %}
2+
<div id="discourse-comments" class="mt-5"></div>
3+
4+
<script>
5+
DiscourseEmbed = {
6+
discourseUrl: 'https://talk.typo3.org/',
7+
discourseEmbedUrl: '[Topic on docs.typo3.org]({{ getPermalink(node.sectionNode) }})'
8+
};
9+
10+
(function () {
11+
var d = document.createElement('script');
12+
d.type = 'text/javascript';
13+
d.async = true;
14+
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
15+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
16+
})();
17+
</script>
18+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace T3Docs\Typo3DocsTheme\Compiler\NodeTransformers;
15+
16+
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
17+
use phpDocumentor\Guides\Compiler\NodeTransformer;
18+
use phpDocumentor\Guides\Nodes\DocumentNode;
19+
use phpDocumentor\Guides\Nodes\Node;
20+
use phpDocumentor\Guides\Nodes\SectionNode;
21+
use T3Docs\Typo3DocsTheme\Nodes\Typo3TalkNode;
22+
23+
/** @implements NodeTransformer<DocumentNode|SectionNode|Typo3TalkNode> */
24+
final class Typo3TalkNodeTransformer implements NodeTransformer
25+
{
26+
/** @var SectionNode[] $sectionStack */
27+
private array $sectionStack = [];
28+
29+
public function __construct(
30+
) {}
31+
32+
public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
33+
{
34+
if ($node instanceof DocumentNode) {
35+
$this->sectionStack = [];
36+
return $node;
37+
}
38+
if ($node instanceof SectionNode) {
39+
$this->sectionStack[] = $node;
40+
return $node;
41+
}
42+
if ($node instanceof Typo3TalkNode && $this->sectionStack !== []) {
43+
$currentSection = end($this->sectionStack);
44+
$node->setSectionNode($currentSection);
45+
}
46+
return $node;
47+
}
48+
49+
public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null
50+
{
51+
if ($node instanceof DocumentNode) {
52+
$this->sectionStack = [];
53+
return $node;
54+
}
55+
if ($node instanceof SectionNode) {
56+
array_pop($this->sectionStack);
57+
return $node;
58+
}
59+
return $node;
60+
}
61+
62+
public function supports(Node $node): bool
63+
{
64+
return $node instanceof DocumentNode || $node instanceof SectionNode || $node instanceof Typo3TalkNode;
65+
}
66+
67+
public function getPriority(): int
68+
{
69+
return 100000;
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace T3Docs\Typo3DocsTheme\Directives;
15+
16+
use phpDocumentor\Guides\Nodes\Node;
17+
use phpDocumentor\Guides\RestructuredText\Directives\BaseDirective;
18+
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
19+
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
20+
use T3Docs\Typo3DocsTheme\Nodes\Typo3TalkNode;
21+
22+
class Typo3TalkDirective extends BaseDirective
23+
{
24+
public function __construct() {}
25+
26+
public function getName(): string
27+
{
28+
return 'typo3:talk';
29+
}
30+
31+
public function processNode(
32+
BlockContext $blockContext,
33+
Directive $directive,
34+
): Node {
35+
return new Typo3TalkNode();
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace T3Docs\Typo3DocsTheme\Nodes;
4+
5+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
6+
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
7+
use phpDocumentor\Guides\Nodes\SectionNode;
8+
use phpDocumentor\Guides\RestructuredText\Nodes\GeneralDirectiveNode;
9+
10+
final class Typo3TalkNode extends GeneralDirectiveNode
11+
{
12+
private ?SectionNode $sectionNode = null;
13+
public function __construct(
14+
) {
15+
16+
parent::__construct('typo3:talk', '', new InlineCompoundNode([new PlainTextInlineNode('')]));
17+
}
18+
19+
public function getSectionNode(): ?SectionNode
20+
{
21+
return $this->sectionNode;
22+
}
23+
24+
public function setSectionNode(?SectionNode $sectionNode): void
25+
{
26+
$this->sectionNode = $sectionNode;
27+
}
28+
}

packages/typo3-docs-theme/src/Twig/TwigExtension.php

+27
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ public function getFunctions(): array
9999
new TwigFunction('isRenderedForDeployment', $this->isRenderedForDeployment(...)),
100100
new TwigFunction('replaceLineBreakOpportunityTags', $this->replaceLineBreakOpportunityTags(...), ['is_safe' => ['html'], 'needs_context' => false]),
101101
new TwigFunction('filterAllowedSearchFacets', $this->filterAllowedSearchFacets(...), ['is_safe' => ['html'], 'needs_context' => false]),
102+
new TwigFunction('getPermalink', $this->getPermalink(...), ['is_safe' => ['html'], 'needs_context' => true]),
102103
];
103104
}
105+
104106
public function filterAllowedSearchFacets(string $value): string
105107
{
106108
$allowed = [
@@ -269,6 +271,31 @@ public function getAnchorIdOfSection(array $context, SectionNode $sectionNode):
269271
}
270272
return '';
271273
}
274+
275+
/**
276+
* @param array{env: RenderContext} $context
277+
*/
278+
public function getPermalink(array $context, SectionNode $sectionNode): string
279+
{
280+
$renderContext = $this->getRenderContext($context);
281+
$interlink = $this->themeSettings->getSettings('interlink_shortcode');
282+
if ($interlink === '') {
283+
$this->logger->warning('A permalink can only be generated if "interlink_shortcode" is set in the guides.xml. ', $renderContext->getLoggerInformation());
284+
return '';
285+
}
286+
$anchorId = '';
287+
foreach ($sectionNode->getChildren() as $childNode) {
288+
if ($childNode instanceof AnchorNode) {
289+
$anchorId = $this->anchorNormalizer->reduceAnchor($childNode->toString());
290+
break;
291+
}
292+
}
293+
if ($anchorId === '') {
294+
$this->logger->warning('The surrounding section has no anchor. ', $renderContext->getLoggerInformation());
295+
}
296+
return 'https://docs.typo3.org/permalink/' . $interlink . ':' . $anchorId;
297+
}
298+
272299
/**
273300
* @param array{env: RenderContext} $context
274301
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- content start -->
2+
<section class="section" id="talk-typo3-org" data-rst-anchor="start">
3+
<a id="start"></a>
4+
<h1>talk.typo3.org<a class="headerlink" href="#talk-typo3-org" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"><i class="fa-solid fa-paragraph"></i></a></h1>
5+
<div id="discourse-comments" class="mt-5"></div>
6+
7+
<script>
8+
DiscourseEmbed = {
9+
discourseUrl: 'https://talk.typo3.org/',
10+
discourseEmbedUrl: '[Topic on docs.typo3.org](https://docs.typo3.org/permalink/changelog:start)'
11+
};
12+
13+
(function () {
14+
var d = document.createElement('script');
15+
d.type = 'text/javascript';
16+
d.async = true;
17+
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
18+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
19+
})();
20+
</script>
21+
22+
</section>
23+
<!-- content end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides
3+
xmlns="https://www.phpdoc.org/guides"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://www.phpdoc.org/guides vendor/phpdocumentor/guides-cli/resources/schema/guides.xsd"
6+
>
7+
<extension class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension"
8+
typo3-core-preferred="main"
9+
interlink-shortcode="changelog"
10+
/>
11+
<project title="Core"
12+
release="main"
13+
version="main"
14+
copyright="since 1997 by the TYPO3 contributors"
15+
/>
16+
</guides>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.. _start:
3+
4+
==============
5+
talk.typo3.org
6+
==============
7+
8+
.. typo3:talk::

0 commit comments

Comments
 (0)