PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / llms-txt / domain / markdown / llms-txt-renderer.php

llms-txt-renderer.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/llms-txt/domain/markdown/llms-txt-renderer.php

63 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Llms_Txt\Domain\Markdown;
5
6 use Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Sections\Section_Interface;
7
8 /**
9 * The renderer of the LLMs.txt file.
10 */
11 class Llms_Txt_Renderer {
12
13 /**
14 * The sections.
15 *
16 * @var Section_Interface[]
17 */
18 private $sections;
19
20 /**
21 * Adds a section.
22 *
23 * @param Section_Interface $section The section to add.
24 *
25 * @return void
26 */
27 public function add_section( Section_Interface $section ): void {
28 $this->sections[] = $section;
29 }
30
31 /**
32 * Returns the sections.
33 *
34 * @return Section_Interface[]
35 */
36 public function get_sections(): array {
37 return $this->sections;
38 }
39
40 /**
41 * Renders the items of the bucket.
42 *
43 * @return string
44 */
45 public function render(): string {
46 if ( empty( $this->sections ) ) {
47 return '';
48 }
49
50 $rendered_sections = [];
51 foreach ( $this->sections as $section ) {
52 $section_content = $section->render();
53 if ( $section_content === '' ) {
54 continue;
55 }
56
57 $rendered_sections[] = $section->get_prefix() . $section_content . \PHP_EOL;
58 }
59
60 return \implode( \PHP_EOL, $rendered_sections );
61 }
62 }
63