-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved SEO (meta tags support) #1235
Comments
Interesting thought. Thanks for the detailed issue. yeah we can do this, though I would implement this as this $docsify= {
...
meta: [
{type: '', content: '' }
]
...
} these will create new meta tags and append it at the end of the head $docsify= {
...
meta: `<meta name="" content="" >
<meta name="" content="" >
`
...
} and this will simply append at the end. would love to hear others suggestions. |
And would be able to add that I would prefer the former :) |
umm, yea I missed this that would be implied to an only single page, We need some discussion about the approach or perhaps a PoC, cc @docsifyjs/core |
should be supported by every md file, |
We need to read the meta data from the markdown file then. ---
meta1:
meta2:
--- but this has an issue, our markdown parser I guess doesn't explicitly tells that whether they are markdown metadata or not. |
Yes, we may need to use a regular to match, similar to the emoji matching See what others think. |
I think we need make docsify configurations in content have the specific prefix or symbol , such as ---
meta1:
meta2:
--- this way seems incompatible with the yaml font matter (#1129) for docsify. |
Does changing the meta tags at runtime (each time we change pages) have any effect on the browser? If not, then thus is good only with SSR (or the upcoming static site generation). Basic spiders/crawlers only read meta tags on the initial page load. If we modify them later, it has no effect. Do we need this at runtime? Might be good for anyone with SSR though. |
I think this gets into "how does Google's search algorithm work?" territory. I'm not enough of an SEO expert to know which tool(s) we could leverage to test client-side generated Maybe Google Structured Data can help? It looks like it can be generated with JavaScript and we can use the Rich Results Test tool to test our implementation. The downside to this approach (assuming it works as we expect) is that this is Google-specific. Ideally, we'd address SEO issues for all search engines, not just Google. |
This is suitable for doing when generating static html in v5. |
We don't need new syntax for this. Just If we want new syntax, it can be an additional feature for later, after this one. |
The only way we can be 100% sure we adress all search engines is having this functionality for SSR and static site generation and encouraging people to use those instead of the live markdown rendering. We can also just add/remove the meta tags at runtime which is simple (and assume some crawler might be smart enough to trigger route changes and read the dynamically-updated meta tags), but I don't think we can make any guarantees on whether that's actually useful (I've never heard of that being useful, but who knows). If the dynamic generation is part of the normal markdown processing, then it should just work with SSR and static generation too.
I think that's a totally different feature, that we can tackle apart from (or before/after) this one, if we wish to. |
I think static generation can be a 4.x non-breaking feature, if we get to it before we get to v5. |
We're talking about different things. Q: Can we improve SEO for docsify sites? Google Structured Data was offered as a way to address the uncertainty of A3 and address @trusktr's "Does changing the meta tags at runtime (each time we change pages) have any effect on the browser?" question. Google's documentation states specifically that this SEO-related information can be generated on the client, which would allow us to improve SEO for client-side only docsify sites. It's not about a new syntax; it's about improving SEO for the sites that need it most (client-side rendering) that also (I assume) make up the vast majority of docsify users. For the record, I'm not proposing we should go this route, only that we could explore it if client-side After a little digging, it looks like client-side generated |
That's a good summary. Note, SSR works already in my PR with a simple fix, but I'm trying to also add tests for it. In all cases, the markdown output will have meta tags. In case of A3, a post render step moves the meta tags to the head with DOM methods. In cases of A1 and A2, a post render step moves the meta tags with string methods.
Is there any limitation? For example, does it need to be generated with If there is some way for Google to wait for the data to be ready, maybe we can re-write meta tags into Google Structured Data so the Docsify user can just use the cross-browser tags? |
Dunno. I own about 10 minutes worth of knowledge on Google Structured Data. :)
That's what I was thinking with the original suggestion. If we have page-specific meta data provided via YAML, there's nothing preventing us from generating One important note: apparently the time of injection matters, so waiting until after a request for content has completed so we can get meta information from each markdown file may not work. Although I don't love this idea, injecting |
made a jekyll theme from docsify SEO supported still need your help! |
You can trivially inject meta like this: index.html <title>Foo</title>
+ <meta name="description" content>
+ <meta name="keywords" content> SEO plugin'use strict';
/*
* Update the page info based on frontmatter data or on the configurated
* generator.
*/
(function (window) {
function meta(name, content) {
document.querySelector(`meta[name="${name}"]`).content = content || ''
}
function plugin(hook, vm) {
const refreshInfo = () => {
const { config, route, frontmatter } = vm
const { description, keywords } = frontmatter || {}
const entries = { description, keywords }
for (const key in entries) {
var value = entries[key]
if (value === undefined) {
const defaultValue = config.seo?.[key]
if (typeof defaultValue === 'function') value = defaultValue(route, frontmatter || {})
else value = defaultValue
}
meta(key, value)
}
}
hook.init(refreshInfo)
hook.doneEach(refreshInfo)
}
window.$docsify = window.$docsify || {}
window.$docsify.plugins = window.$docsify.plugins || []
window.$docsify.plugins.push(plugin)
})(this) ConfigOptional: For each meta, provide either a string or a function that returns the value. window.$docsify = Object.assign(window.$docsify || {}, {
+ seo: {
+ description: (route, frontmatter) => {
+ if (route.path.startsWith('/ja/')) return `一般的な説明`
+ else return `Some default description`
+ },
+ keywords: `foo, bar, baz`,
+ },
pagination: { |
Hey! Is there any update? Any blocker preventing this feature from being part of Docsify? |
Hey @dialex -- I believe there are two reasons why this hasn't been worked on:
Injecting I created a quick "proof-of-concept" to demonstrate how this might be implemented via a plugin: The easiest way to see what the plugin is doing is by using the browser's dev tools to see the updates happening the When I say "proof of concept", I mean it. The POC doesn't handle a number of common meta tag use cases such as multiple attributes on a single tag and intelligently removing meta tags injected from previous pages. Those things could be added easily enough as well though. |
Feature request
What problem does this feature solve?
It improves SEO of pages generated by Docsify. It makes it easier for search engines to find the relevant content, and when a user shares a link to a Docsify page, the rendered preview is more accurate (title, description and image).
Example (diff pages, same SEO 😢 ):
What does the proposed API look like?
Marp allows you to write slides using Markdown, and each file has a small header like this:
Docsify could have something similar that would allow us to define the meta tags of each page. Example:
How should this be implemented in your opinion?
I checked if it was possible to hack it with the current Docsify version by hardcoding HTML tags in the
.md
file.It didn't work. Those tags were added inside
<body> ... <article>
, but we need them to exist in the<head>
section.I propose this flow:
meta-title
) and override it's value.Example:
Are you willing to work on this yourself?
I don't think I have enough JS and Docsify knowledge to develop this feature. But I can (beta) test it!
The text was updated successfully, but these errors were encountered: