mmistakes / minimal-mistakes

:triangular_ruler: Jekyll theme for building a personal site, blog, project documentation, or portfolio.
https://mmistakes.github.io/minimal-mistakes/
MIT License
12.41k stars 25.57k forks source link

Replace custom seo.html with Jekyll SEO Tag plugin #324

Closed ddd-workshop closed 4 years ago

ddd-workshop commented 8 years ago

Recently announced by GitHub: https://github.com/blog/2162-better-discoverability-for-github-pages-sites

mmistakes commented 8 years ago

Sort of. I originally planned to use the Jekyll SEO Tag plugin that comes along with GitHub Pages but it didn't fully support everything the theme does (eg: Twitter Summary cards with large images).

So I took what the plugin did and baked it into the theme so I could enhance and build off of it.

If for whatever reason you'd rather use the native plugin instead of my customizations you can rip out {% include seo.html %} from /_includes/head.html and replace with {{ seo }} and you're good to go.

mmistakes commented 8 years ago

Followup. The Jekyll SEO Tag plugin has made a lot of nice updates and now supports everything I was custom rolling into the theme and would love to swap it in.

Only thing is it would be a bit more work if you want to include feature images as meta data for Twitter Cards and Open Graph. The variable names are different so you'd have to manually specify them and edit any old content.

Jekyll SEO Tag MM theme
page.image page.header.image
site.logo site.og_image

I tried using some Liquid assign tags to override variables and placed that before {% seo %} in head.html but it didn't seem to work.

{% if page.header.image contains "://" %}
  {% assign page.image = page.header.image %}
{% else %}
  {% assign page.image = page.header.image | prepend: "/images/" | prepend: base_path %}
{% endif %}

{% if site.og_image contains "://" %}
  {% assign site.logo = site.og_image %}
{% else %}
  {% assign site.logo = site.og_image | prepend: "/images/" | prepend: base_path %}
{% endif %}

{% seo %}

If anyone has any ideas of how to pull in images to be used with {{ seo }} without having to change variable names in the theme or edit YAML Front Matter in posts/pages/collections that would be great.

mmistakes commented 7 years ago

Workaround. Use YAML anchors to avoid duplicating values.

Example:

header:
  image: &image /assets/images/filename.jpg
image: *image

or

header:
  image: &image /assets/images/filename.jpg
image: 
  path: *image
ghost commented 7 years ago

@mmistakes need a hand with this? It'd be great to get this into the theme. Related discussion occurring here: https://github.com/jekyll/jekyll-seo-tag/issues/159

mmistakes commented 7 years ago

Sure @jhabdas if you want to work on a PR. I've been putting if off because I didn't want to deal with disrupting the current behavior and any issues that are going to flood in over "why aren't my Twitter cards showing up anymore" due to the header.image change :wink:

ghost commented 7 years ago

@mmistakes cool. gimme a few minutes. I'll work on it now.

mmistakes commented 7 years ago

That and it's going to deprecate the configurable <title> separator and revert back to -. But I'm cool with that, just need to remember to add a note about in the docs. https://mmistakes.github.io/minimal-mistakes/docs/configuration/#site-title

mmistakes commented 7 years ago

@jhabdas RE: auto-adding the {% seo %} tag from the plugin I was thinking something like this in case a user wants to rip it out, at least they get SEO optimized <title> elements and the canonical tag.

{% if site.gems contains 'jekyll-seo-tag' %}
    {% comment %}
    Add metadata for search engines and social networks if jekyll-seo-tag plugin is enabled
    {% endcomment %}
    {% include head-seo.html %}
{% else %}
    <title>{% if page.title %}{{ page.title | escape }}{% else %}{{ site.title | escape }}{% endif %}</title>
    <meta name="description" content="{{ page.excerpt | default: site.description | strip_html | normalize_whitespace | truncate: 160 | escape }}">
    <link rel="canonical" href="{{ page.url | replace:'index.html','' | absolute_url }}">
{% endif %}

_includes/head-seo.html

{% seo %}
ghost commented 7 years ago

That and it's going to deprecate the configurable separator and revert back to -. But I'm cool with that, just need to remember to add a note about that in the docs.</p> </blockquote> <p>There's an open issue against the SEO tag for title separator customization: <a href="https://github.com/jekyll/jekyll-seo-tag/issues/121">https://github.com/jekyll/jekyll-seo-tag/issues/121</a></p> <p>Be great if you could upvote the issue.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/mmistakes"><img src="https://avatars.githubusercontent.com/u/1376749?v=4" />mmistakes</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>Upvoted. I'm picky about the visual appearance of that stuff so that's why I originally baked it into the theme. In the grand scheme of SEO it probably doesn't matter in the least so I can see why it might not make it into the plugin.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/ghost"><img src="https://avatars.githubusercontent.com/u/10137?v=4" />ghost</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>I took a good long look at this and reached the conclusion there's not much to gain from adding support for <a href="https://github.com/jekyll/jekyll-seo-tag">Jekyll SEO Tag</a> to this theme. Here's why:</p> <ul> <li>Made Mistakes theme already does a good job at SEO on its own, and is a fine example of how to roll your own SEO (and that's nice to have to gain an understanding of how to do things without relying on a dependency).</li> <li>Adding the Jekyll SEO Tag will result in many exceptions to the existing documentation, both in the standard configuration as well as the multi-author support.</li> <li>There will be namespace clashes between theme and plugin both in the config and <code>authors.yml</code> which, if integrated, would cause headaches and potentially break existing theme features. And I'm not sure there are enough YAML anchors in the world to address that.</li> <li>Jekyll SEO Tag gem, though available for GitHub Pages sites, needs more work IMHO. I would encourage those interested in attempting to integrate it to work with the maintainers of the plugin to continue making improvements (and ideally add some namespacing of some kind).</li> </ul> <p>For the adventurous <em>using the gemified theme</em>, you can add support for Jekyll Tag gem by doing the following:</p> <ol> <li> <p>Install the versioned plugin dependency to your site-level <code>Gemfile</code></p> <pre><code class="language-shell">bundle install gemrat gemrat jekyll-seo-tag</code></pre> </li> <li> <p>Add <code>jekyll-seo-tag</code> to the <code>gems</code> array in your site <code>_config.yml</code></p> </li> <li> <p>Copy contents of theme <code>_includes/seo.html</code> file to <code>_includes/head/seo.html</code> in your site after doing:</p> <pre><code class="language-shell">mkdir -p _includes/head && touch _includes/head/seo.html</code></pre> </li> <li> <p>Create a site-level <code>_includes/seo.html</code> with the following contents:</p> <pre><code class="language-liquid">{% if site.gems contains 'jekyll-seo-tag' %} {% comment %} Add metadata for search engines and social networks if jekyll-seo-tag plugin is enabled @see https://github.com/jekyll/jekyll-seo-tag/ for usage instructions {% endcomment %} {% seo %} {% else %} {% comment %} Otherwise use custom theme override {% endcomment %} {% include head/seo.html %} {% endif %}</code></pre> </li> <li> <p>And then follow the plugin <a href="https://github.com/jekyll/jekyll-seo-tag">setup and usage instructions</a>.</p> </li> </ol> <p>😅 </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/mmistakes"><img src="https://avatars.githubusercontent.com/u/1376749?v=4" />mmistakes</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>@jhabdas Pretty much the same conclusions I drew which is part of the reason I've held off tackleling this. My main motivation was to leverage the plugin so I wouldn't have to maintain the SEO portion of the theme and piggy back on improvements they were regularly making.</p> <p>But I agree, probably too many things to fight against to do it and likely lose a few custom additions the theme accounts for. Is there anything there plugin does the theme doesn't that we should add? </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/ghost"><img src="https://avatars.githubusercontent.com/u/10137?v=4" />ghost</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>👍 None that I'm aware of. There're some additional JSON-LD support in the works, though, as we're seeing, mixing several different structured data formats into one plug-in can get a little hairy.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/ghost"><img src="https://avatars.githubusercontent.com/u/10137?v=4" />ghost</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>FYI <a href="https://github.com/jekyll/jekyll-seo-tag/issues/161">https://github.com/jekyll/jekyll-seo-tag/issues/161</a></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/stale[bot]"><img src="https://avatars.githubusercontent.com/in/1724?v=4" />stale[bot]</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/djrare"><img src="https://avatars.githubusercontent.com/u/18430059?v=4" />djrare</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Issue webpage https;\(Basic)-www.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/djrare"><img src="https://avatars.githubusercontent.com/u/18430059?v=4" />djrare</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Comment</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>