mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
feat: Enhanced SEO and Page Description Functionality
- Added structured data support to optimize SEO performance for the homepage and article pages. - Added an SEO enhancement script to generate more detailed page descriptions and relevant keywords.
This commit is contained in:
1 parent
03e5928b1e
commit
6be4403e9d
4 files changed
+462
-8
No files matched your search
+22
-7
@@ -7,9 +7,9 @@ title: CheatSheets.zip
|
||||
subtitle: "Ultimate Cheat for Developers"
|
||||
description: "Share quick reference and cheat sheet for developers"
|
||||
keywords: cheat,sheet,cheatsheets,reference,programming,code table,snippets,linux,command,shortcuts,developers
|
||||
author: CheatSheets.zip
|
||||
author: Fechin
|
||||
language: en
|
||||
timezone: ""
|
||||
timezone: "UTC"
|
||||
|
||||
# URL
|
||||
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
|
||||
@@ -60,13 +60,29 @@ index_generator:
|
||||
|
||||
# Category & Tag
|
||||
default_category: uncategorized
|
||||
category_map:
|
||||
tag_map:
|
||||
category_map: {}
|
||||
tag_map: {}
|
||||
|
||||
# Metadata elements
|
||||
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
|
||||
meta_generator: false
|
||||
|
||||
# SEO configuration
|
||||
seo:
|
||||
# Default image for social sharing
|
||||
default_image: "/assets/image/preview.png"
|
||||
# Author information
|
||||
author_name: "Fechin"
|
||||
author_url: "https://cheatsheets.zip"
|
||||
# Social media configuration
|
||||
social:
|
||||
twitter: "Fechin"
|
||||
github: "Fechin/reference"
|
||||
# Site type
|
||||
site_type: "Educational Technology Platform"
|
||||
# Target audience
|
||||
target_audience: "Developers, Programmers, System Administrators"
|
||||
|
||||
# Date / Time format
|
||||
## Hexo uses Moment.js to parse and display date
|
||||
## You can customize the date format as defined in
|
||||
@@ -83,10 +99,10 @@ pagination_dir: page
|
||||
|
||||
# Include / Exclude file(s)
|
||||
## include:/exclude: options only apply to the 'source/' folder
|
||||
include:
|
||||
include: []
|
||||
exclude:
|
||||
- ".github"
|
||||
ignore:
|
||||
ignore: []
|
||||
|
||||
# Extensions
|
||||
## Plugins: https://hexo.io/plugins/
|
||||
@@ -112,7 +128,6 @@ excerpt:
|
||||
# Deployment
|
||||
## Docs: https://hexo.io/docs/deployment.html
|
||||
deploy:
|
||||
# - type: cjh_google_url_submitter
|
||||
- type: cjh_bing_url_submitter
|
||||
- type: cjh_baidu_url_submitter
|
||||
|
||||
|
||||
@@ -13,6 +13,23 @@
|
||||
<meta name="keywords" content="<%- page_keywords() %>"/>
|
||||
<!-- description -->
|
||||
<meta name="description" content="<%- page_description() %>"/>
|
||||
|
||||
<!-- Additional SEO meta tags -->
|
||||
<meta name="author" content="<%- config.author %>"/>
|
||||
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1"/>
|
||||
<% if (is_post()) { %>
|
||||
<meta name="article:author" content="<%- config.title %>"/>
|
||||
<meta name="article:published_time" content="<%- page.date.toISOString() %>"/>
|
||||
<meta name="article:modified_time" content="<%- (page.updated || page.date).toISOString() %>"/>
|
||||
<% if (page.categories && page.categories.length > 0) { %>
|
||||
<meta name="article:section" content="<%- page.categories.toArray()[0].name %>"/>
|
||||
<% } %>
|
||||
<% if (page.tags && page.tags.each) { %>
|
||||
<% page.tags.each(function(tag) { %>
|
||||
<meta name="article:tag" content="<%- tag.name %>"/>
|
||||
<% }); %>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<!-- for social -->
|
||||
<meta property="og:url" content="<%- clean_url(url) %>"/>
|
||||
@@ -22,7 +39,22 @@
|
||||
<meta property="og:image" content="<%- page_image() %>"/>
|
||||
<meta property="og:image:width" content="2276"/>
|
||||
<meta property="og:image:height" content="1240"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:image:alt" content="<%- page_title() %> - <%- config.title %>"/>
|
||||
<meta property="og:type" content="<%= is_post() ? 'article' : 'website' %>"/>
|
||||
<meta property="og:locale" content="en_US"/>
|
||||
<% if (is_post()) { %>
|
||||
<meta property="article:published_time" content="<%- page.date.toISOString() %>"/>
|
||||
<meta property="article:modified_time" content="<%- (page.updated || page.date).toISOString() %>"/>
|
||||
<meta property="article:author" content="<%- config.title %>"/>
|
||||
<% if (page.categories && page.categories.length > 0) { %>
|
||||
<meta property="article:section" content="<%- page.categories.toArray()[0].name %>"/>
|
||||
<% } %>
|
||||
<% if (page.tags && page.tags.each) { %>
|
||||
<% page.tags.each(function(tag) { %>
|
||||
<meta property="article:tag" content="<%- tag.name %>"/>
|
||||
<% }); %>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<!-- twitter share-->
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
@@ -31,6 +63,7 @@
|
||||
<meta name="twitter:creator" content="@<%- config.author %>">
|
||||
<meta name="twitter:description" content="<%- page_description() %>"/>
|
||||
<meta name="twitter:image" content="<%- page_image() %>"/>
|
||||
<meta name="twitter:image:alt" content="<%- page_title() %> - <%- config.title %>"/>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" href="/images/favicon.png?v=1"/>
|
||||
@@ -63,4 +96,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Structured Data for SEO -->
|
||||
<%- partial('_partial/structured-data') %>
|
||||
|
||||
</head>
|
||||
@@ -0,0 +1,217 @@
|
||||
<script type="application/ld+json">
|
||||
<%
|
||||
// Basic Organization data
|
||||
const orgData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Organization",
|
||||
"name": config.title,
|
||||
"url": config.url,
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": config.url + "/assets/logo/icon-192x192.png"
|
||||
},
|
||||
"description": config.description,
|
||||
"sameAs": [
|
||||
"https://github.com/Fechin/reference",
|
||||
"https://x.com/Fechin"
|
||||
]
|
||||
};
|
||||
|
||||
// Basic Website data
|
||||
const websiteData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "WebSite",
|
||||
"name": config.title,
|
||||
"url": config.url,
|
||||
"description": config.description,
|
||||
"publisher": {
|
||||
"@type": "Organization",
|
||||
"name": config.title,
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": config.url + "/assets/logo/icon-192x192.png"
|
||||
}
|
||||
},
|
||||
"potentialAction": {
|
||||
"@type": "SearchAction",
|
||||
"target": {
|
||||
"@type": "EntryPoint",
|
||||
"urlTemplate": config.url + "/?q={search_term_string}"
|
||||
},
|
||||
"query-input": "required name=search_term_string"
|
||||
}
|
||||
};
|
||||
|
||||
let schemaArray = [];
|
||||
|
||||
if (is_home()) {
|
||||
// Homepage: Add Organization and Website schema
|
||||
schemaArray.push(orgData, websiteData);
|
||||
|
||||
// Add ItemList for category display
|
||||
const itemListData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "ItemList",
|
||||
"name": "Developer Cheat Sheets",
|
||||
"description": "Collection of quick reference guides for developers",
|
||||
"numberOfItems": site.posts.length,
|
||||
"itemListElement": []
|
||||
};
|
||||
|
||||
let position = 1;
|
||||
site.posts.sort('date', -1).limit(20).each(function(post) {
|
||||
itemListData.itemListElement.push({
|
||||
"@type": "ListItem",
|
||||
"position": position++,
|
||||
"name": post.title + " Cheat Sheet",
|
||||
"url": config.url + url_for(post.path)
|
||||
});
|
||||
});
|
||||
|
||||
schemaArray.push(itemListData);
|
||||
|
||||
} else if (is_post()) {
|
||||
// Article page: Add TechArticle schema
|
||||
const categoryNames = [];
|
||||
if (page.categories && page.categories.each) {
|
||||
page.categories.each(function(cat) {
|
||||
categoryNames.push(cat.name);
|
||||
});
|
||||
}
|
||||
|
||||
const keywords = [];
|
||||
if (page.tags && page.tags.each) {
|
||||
page.tags.each(function(tag) {
|
||||
keywords.push(tag.name);
|
||||
});
|
||||
}
|
||||
|
||||
const articleData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": page.title + " Cheat Sheet & Quick Reference",
|
||||
"name": page.title + " Cheat Sheet",
|
||||
"description": page_description(),
|
||||
"image": page_image(),
|
||||
"url": clean_url(url),
|
||||
"datePublished": page.date.toISOString(),
|
||||
"dateModified": (page.updated || page.date).toISOString(),
|
||||
"author": {
|
||||
"@type": "Organization",
|
||||
"name": config.title,
|
||||
"url": config.url
|
||||
},
|
||||
"publisher": {
|
||||
"@type": "Organization",
|
||||
"name": config.title,
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": config.url + "/assets/logo/icon-192x192.png"
|
||||
},
|
||||
"url": config.url
|
||||
},
|
||||
"mainEntityOfPage": {
|
||||
"@type": "WebPage",
|
||||
"@id": clean_url(url)
|
||||
},
|
||||
"about": {
|
||||
"@type": "SoftwareApplication",
|
||||
"name": page.title,
|
||||
"applicationCategory": "DeveloperApplication"
|
||||
},
|
||||
"audience": {
|
||||
"@type": "Audience",
|
||||
"audienceType": "Developers, Programmers, System Administrators"
|
||||
},
|
||||
"educationalLevel": "Beginner to Advanced",
|
||||
"learningResourceType": "Quick Reference Guide",
|
||||
"typicalAgeRange": "18-65",
|
||||
"inLanguage": "en"
|
||||
};
|
||||
|
||||
if (categoryNames.length > 0) {
|
||||
articleData.articleSection = categoryNames;
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
articleData.keywords = keywords.join(", ");
|
||||
}
|
||||
|
||||
schemaArray.push(websiteData, articleData);
|
||||
|
||||
// Add BreadcrumbList
|
||||
const breadcrumbData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
"itemListElement": [
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": 1,
|
||||
"name": "Home",
|
||||
"item": config.url
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
if (categoryNames.length > 0) {
|
||||
breadcrumbData.itemListElement.push({
|
||||
"@type": "ListItem",
|
||||
"position": 2,
|
||||
"name": categoryNames[0],
|
||||
"item": config.url + "/#" + categoryNames[0].toLowerCase().replace(/\s+/g, '-')
|
||||
});
|
||||
|
||||
breadcrumbData.itemListElement.push({
|
||||
"@type": "ListItem",
|
||||
"position": 3,
|
||||
"name": page.title + " Cheat Sheet",
|
||||
"item": clean_url(url)
|
||||
});
|
||||
} else {
|
||||
breadcrumbData.itemListElement.push({
|
||||
"@type": "ListItem",
|
||||
"position": 2,
|
||||
"name": page.title + " Cheat Sheet",
|
||||
"item": clean_url(url)
|
||||
});
|
||||
}
|
||||
|
||||
schemaArray.push(breadcrumbData);
|
||||
|
||||
} else if (is_page()) {
|
||||
// Normal page
|
||||
const pageData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "WebPage",
|
||||
"name": page.title,
|
||||
"description": page_description(),
|
||||
"url": clean_url(url),
|
||||
"mainEntity": {
|
||||
"@type": "Organization",
|
||||
"name": config.title,
|
||||
"url": config.url
|
||||
},
|
||||
"breadcrumb": {
|
||||
"@type": "BreadcrumbList",
|
||||
"itemListElement": [
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": 1,
|
||||
"name": "Home",
|
||||
"item": config.url
|
||||
},
|
||||
{
|
||||
"@type": "ListItem",
|
||||
"position": 2,
|
||||
"name": page.title,
|
||||
"item": clean_url(url)
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
schemaArray.push(websiteData, pageData);
|
||||
}
|
||||
%>
|
||||
<%- JSON.stringify(schemaArray, null, 2) %>
|
||||
</script>
|
||||
@@ -0,0 +1,186 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Generate more detailed page descriptions
|
||||
hexo.extend.helper.register('enhanced_page_description', function () {
|
||||
let description = '';
|
||||
|
||||
if (this.is_home()) {
|
||||
description = `${this.config.description} - Quick reference guides for developers, programmers, and system administrators. Find cheat sheets for popular programming languages, tools, and technologies.`;
|
||||
} else if (this.page && this.page.intro && this.page.intro.trim()) {
|
||||
description = this.strip_html(this.markdown(this.page.intro)).substring(0, 155);
|
||||
} else if (this.is_post()) {
|
||||
const categoryNames = [];
|
||||
if (this.page.categories && this.page.categories.each) {
|
||||
this.page.categories.each(function (cat) {
|
||||
categoryNames.push(cat.name);
|
||||
});
|
||||
}
|
||||
|
||||
const categoryText = categoryNames.length > 0 ? `${categoryNames[0]} ` : '';
|
||||
description = `${this.page.title} cheat sheet and quick reference guide. Essential ${categoryText}shortcuts, commands, and tips for developers and system administrators.`;
|
||||
} else if (this.page && this.page.content) {
|
||||
description = this.strip_html(this.page.content).substring(0, 155);
|
||||
} else {
|
||||
description = this.config.description || '';
|
||||
}
|
||||
|
||||
// Clean up description text
|
||||
description = description.replace(/[\r\n\s\s+]+/g, ' ').trim();
|
||||
|
||||
// Ensure description ends with a period
|
||||
if (
|
||||
description &&
|
||||
!description.endsWith('.') &&
|
||||
!description.endsWith('!') &&
|
||||
!description.endsWith('?')
|
||||
) {
|
||||
description += '.';
|
||||
}
|
||||
|
||||
return description;
|
||||
});
|
||||
|
||||
// Generate article reading time estimate
|
||||
hexo.extend.helper.register('reading_time', function (content) {
|
||||
if (!content) return '2 min read';
|
||||
|
||||
const wordsPerMinute = 200;
|
||||
const textContent = this.strip_html(content);
|
||||
const wordCount = textContent.split(/\s+/).length;
|
||||
const readingTime = Math.ceil(wordCount / wordsPerMinute);
|
||||
|
||||
return `${readingTime} min read`;
|
||||
});
|
||||
|
||||
// Generate related keywords
|
||||
hexo.extend.helper.register('related_keywords', function () {
|
||||
let keywords = [];
|
||||
|
||||
if (this.is_post()) {
|
||||
// Basic keywords
|
||||
keywords.push('cheat sheet', 'quick reference', 'guide', 'tutorial');
|
||||
|
||||
// Add page title keywords
|
||||
if (this.page.title) {
|
||||
keywords.push(this.page.title.toLowerCase());
|
||||
keywords.push(`${this.page.title.toLowerCase()} guide`);
|
||||
keywords.push(`${this.page.title.toLowerCase()} commands`);
|
||||
}
|
||||
|
||||
// Add category keywords
|
||||
if (this.page.categories && this.page.categories.each) {
|
||||
this.page.categories.each(function (cat) {
|
||||
keywords.push(cat.name.toLowerCase());
|
||||
});
|
||||
}
|
||||
|
||||
// Add tag keywords
|
||||
if (this.page.tags && this.page.tags.each) {
|
||||
this.page.tags.each(function (tag) {
|
||||
keywords.push(tag.name.toLowerCase());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return [...new Set(keywords)].join(', ');
|
||||
});
|
||||
|
||||
// Generate page type
|
||||
hexo.extend.helper.register('page_type', function () {
|
||||
if (this.is_home()) return 'homepage';
|
||||
if (this.is_post()) return 'cheatsheet';
|
||||
if (this.is_page()) return 'page';
|
||||
return 'other';
|
||||
});
|
||||
|
||||
// Generate estimated word count
|
||||
hexo.extend.helper.register('word_count', function (content) {
|
||||
if (!content) return 0;
|
||||
const textContent = this.strip_html(content);
|
||||
return textContent.split(/\s+/).length;
|
||||
});
|
||||
|
||||
// Check if there is a table of contents
|
||||
hexo.extend.helper.register('has_toc', function (content) {
|
||||
if (!content) return false;
|
||||
|
||||
// Check if there are title elements
|
||||
const headingRegex = /<h[1-6][^>]*>/gi;
|
||||
const headings = content.match(headingRegex);
|
||||
|
||||
return headings && headings.length >= 3;
|
||||
});
|
||||
|
||||
// Generate breadcrumb data
|
||||
hexo.extend.helper.register('breadcrumb_data', function () {
|
||||
const breadcrumbs = [];
|
||||
|
||||
// Homepage link
|
||||
breadcrumbs.push({
|
||||
name: 'Home',
|
||||
url: this.config.url,
|
||||
position: 1
|
||||
});
|
||||
|
||||
if (this.is_post()) {
|
||||
// Category link
|
||||
if (this.page.categories && this.page.categories.length > 0) {
|
||||
const mainCategory = this.page.categories.toArray()[0];
|
||||
breadcrumbs.push({
|
||||
name: mainCategory.name,
|
||||
url: `${this.config.url}/#${mainCategory.name.toLowerCase().replace(/\s+/g, '-')}`,
|
||||
position: 2
|
||||
});
|
||||
|
||||
// Current page
|
||||
breadcrumbs.push({
|
||||
name: `${this.page.title} Cheat Sheet`,
|
||||
url: this.clean_url(this.url),
|
||||
position: 3
|
||||
});
|
||||
} else {
|
||||
// Current page
|
||||
breadcrumbs.push({
|
||||
name: `${this.page.title} Cheat Sheet`,
|
||||
url: this.clean_url(this.url),
|
||||
position: 2
|
||||
});
|
||||
}
|
||||
} else if (this.is_page()) {
|
||||
// Current page
|
||||
breadcrumbs.push({
|
||||
name: this.page.title,
|
||||
url: this.clean_url(this.url),
|
||||
position: 2
|
||||
});
|
||||
}
|
||||
|
||||
return breadcrumbs;
|
||||
});
|
||||
|
||||
// Generate technical article specific meta information
|
||||
hexo.extend.helper.register('tech_article_meta', function () {
|
||||
if (!this.is_post()) return {};
|
||||
|
||||
const meta = {
|
||||
difficulty: 'Beginner to Advanced',
|
||||
audience: 'Developers, Programmers, System Administrators',
|
||||
type: 'Quick Reference Guide',
|
||||
format: 'Cheat Sheet'
|
||||
};
|
||||
|
||||
// Adjust difficulty based on category
|
||||
if (this.page.categories && this.page.categories.each) {
|
||||
this.page.categories.each(function (cat) {
|
||||
if (cat.name.includes('Linux') || cat.name.includes('Command')) {
|
||||
meta.difficulty = 'Intermediate to Advanced';
|
||||
meta.audience = 'System Administrators, DevOps Engineers, Developers';
|
||||
} else if (cat.name.includes('Programming')) {
|
||||
meta.audience = 'Developers, Software Engineers, Programmers';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return meta;
|
||||
});
|
||||
Reference in new issue
Block a user