PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
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 19.0 All 129 releases
wordpress-seo / src / llms-txt / domain / markdown / sections / intro.php

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

99 lines 1.9 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.MaxExceeded
4 namespace Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Sections;
5
6 use Yoast\WP\SEO\Llms_Txt\Application\Markdown_Escaper;
7 use Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Items\Link;
8
9 /**
10 * Represents the intro section.
11 */
12 class Intro implements Section_Interface {
13
14 /**
15 * The intro content.
16 *
17 * @var string
18 */
19 private $intro_content;
20
21 /**
22 * The intro links.
23 *
24 * @var Link[]
25 */
26 private $intro_links = [];
27
28 /**
29 * Class constructor.
30 *
31 * @param string $intro_content The intro content.
32 * @param Link[] $intro_links The intro links.
33 */
34 public function __construct( string $intro_content, array $intro_links ) {
35 $this->intro_content = $intro_content;
36
37 foreach ( $intro_links as $link ) {
38 $this->add_link( $link );
39 }
40 }
41
42 /**
43 * Returns the prefix of the intro section.
44 *
45 * @return string
46 */
47 public function get_prefix(): string {
48 return '';
49 }
50
51 /**
52 * Adds a link to the intro section.
53 *
54 * @param Link $link The link to add.
55 *
56 * @return void
57 */
58 public function add_link( Link $link ): void {
59 $this->intro_links[] = $link;
60 }
61
62 /**
63 * Returns the content of the intro section.
64 *
65 * @return string
66 */
67 public function render(): string {
68 if ( \count( $this->intro_links ) === 0 ) {
69 return $this->intro_content;
70 }
71
72 $rendered_links = \array_map(
73 static function ( $link ) {
74 return $link->render();
75 },
76 $this->intro_links,
77 );
78
79 $this->intro_content = \sprintf(
80 $this->intro_content,
81 ...$rendered_links,
82 );
83 return $this->intro_content;
84 }
85
86 /**
87 * Escapes the markdown content.
88 *
89 * @param Markdown_Escaper $markdown_escaper The markdown escaper.
90 *
91 * @return void
92 */
93 public function escape_markdown( Markdown_Escaper $markdown_escaper ): void {
94 foreach ( $this->intro_links as $link ) {
95 $link->escape_markdown( $markdown_escaper );
96 }
97 }
98 }
99