aerni / statamic-advanced-seo

Comprehensive SEO addon for Statamic with flexibility in mind
https://statamic.com/addons/aerni/advanced-seo
10 stars 5 forks source link

Strip Tags from title and description #127

Closed netwaretcs closed 1 month ago

netwaretcs commented 4 months ago

In some cases, titles and descriptions are taken directly from markdown fields. In my case, for example, I had the problem of p and strong tags being written in the meta title and meta description. I tried putting in the defaults {{ title | strip_tags }} but it didn't seem to work, so I thought I would come up with this pull request.

aerni commented 4 months ago

What do you mean by In some cases, titles and descriptions are taken directly from markdown fields.? Can you give me an example how to reproduce this?

netwaretcs commented 4 months ago

In articles collection we use "markdown" for the title field.

So if the title is: This is a **Title**

The tag become: <code><title><p>This is a <strong>title</strong</p></title></code></p> <p>Same thing for description, og:title...</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/aerni"><img src="https://avatars.githubusercontent.com/u/23167701?v=4" />aerni</a> commented <strong> 4 months ago</strong> </div> <div class="markdown-body"> <p>I can't reproduce this issue. Using the <code>strip_tags</code> modifier in the title field works for me. </p> <p>Generally, I think it is a good idea to strip tags and any other unsupported characters like line breaks and such from meta fields. But I'd rather implement it on a deeper level, so it also works with GraphQL.</p> <p>For now, you should be able to publish the views of this addon to implement the solution as per this PR. But I'm curious as to why the <code>strip_tags</code> modifier didn't work for you in the first place?</p> <img width="358" alt="CleanShot 2024-02-27 at 15 01 17@2x" src="https://github.com/aerni/statamic-advanced-seo/assets/23167701/a2cbbbea-9137-44d4-94b2-0cefd249af00"> <img width="891" alt="CleanShot 2024-02-27 at 15 01 58@2x" src="https://github.com/aerni/statamic-advanced-seo/assets/23167701/99917c27-3d72-427e-b65c-a943eca452af"> <img width="398" alt="CleanShot 2024-02-27 at 15 02 09@2x" src="https://github.com/aerni/statamic-advanced-seo/assets/23167701/48706a5e-eae0-48ca-bd81-a0a380863685"> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/netwaretcs"><img src="https://avatars.githubusercontent.com/u/67137992?v=4" />netwaretcs</a> commented <strong> 4 months ago</strong> </div> <div class="markdown-body"> <p>I will try to debug the problem so that I can give you more details.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/aerni"><img src="https://avatars.githubusercontent.com/u/23167701?v=4" />aerni</a> commented <strong> 1 month ago</strong> </div> <div class="markdown-body"> <p>Is this still an issue for you? </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/aerni"><img src="https://avatars.githubusercontent.com/u/23167701?v=4" />aerni</a> commented <strong> 1 month ago</strong> </div> <div class="markdown-body"> <p>I'm closing this PR as it appears inactive. Feel free to comment if you still think it is needed.</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>