Skip to content

Commit c5af76d

Browse files
authored
Открывает внешние ссылки в эпизодах в новой вкладке (#406)
1 parent 4538859 commit c5af76d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/eleventy-config/transforms.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@ export default function(eleventyConfig) {
155155
return content;
156156
});
157157

158+
// открытие ссылок в новой вкладке внутри страниц эпизодов
159+
eleventyConfig.addTransform('podcast-content', async function(content) {
160+
if (!this.page?.outputPath?.endsWith?.('html')) {
161+
return content;
162+
}
163+
164+
// игнорируем страницы, не попадающие под url вида `/podcast/<номер эпизода>/`
165+
if (!(/\podcast\/\d+\//.test(this.page?.url))) {
166+
return content;
167+
}
168+
169+
const { document } = parseHTML(content);
170+
171+
for (const link of document.querySelectorAll('.podcast__content a[href^="http"]')) {
172+
link.setAttribute('target', '_blank');
173+
link.setAttribute('rel', 'noopener');
174+
}
175+
176+
return document.toString();
177+
});
178+
158179
// добавление id на заголовки и кнопок для копирования ссылок
159180
eleventyConfig.addTransform('content-headings', async function(content) {
160181
if (!this.page?.outputPath?.endsWith?.('html')) {

0 commit comments

Comments
 (0)