From 6be4403e9db9bc2a5e9730ec8e14761fb7f2c2b8 Mon Sep 17 00:00:00 2001 From: Fechin Date: Tue, 1 Jul 2025 14:43:30 +0800 Subject: [PATCH] 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. --- _config.yml | 29 ++- themes/coo/layout/_partial/head.ejs | 38 ++- .../coo/layout/_partial/structured-data.ejs | 217 ++++++++++++++++++ themes/coo/scripts/seo-enhanced.js | 186 +++++++++++++++ 4 files changed, 462 insertions(+), 8 deletions(-) create mode 100644 themes/coo/layout/_partial/structured-data.ejs create mode 100644 themes/coo/scripts/seo-enhanced.js diff --git a/_config.yml b/_config.yml index 80ef853..8963320 100644 --- a/_config.yml +++ b/_config.yml @@ -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 diff --git a/themes/coo/layout/_partial/head.ejs b/themes/coo/layout/_partial/head.ejs index be1623d..2bebe29 100644 --- a/themes/coo/layout/_partial/head.ejs +++ b/themes/coo/layout/_partial/head.ejs @@ -13,6 +13,23 @@ + + + + + <% if (is_post()) { %> + + + + <% if (page.categories && page.categories.length > 0) { %> + + <% } %> + <% if (page.tags && page.tags.each) { %> + <% page.tags.each(function(tag) { %> + + <% }); %> + <% } %> + <% } %> @@ -22,7 +39,22 @@ - + + + + <% if (is_post()) { %> + + + + <% if (page.categories && page.categories.length > 0) { %> + + <% } %> + <% if (page.tags && page.tags.each) { %> + <% page.tags.each(function(tag) { %> + + <% }); %> + <% } %> + <% } %> @@ -31,6 +63,7 @@ + @@ -63,4 +96,7 @@ } + + <%- partial('_partial/structured-data') %> + diff --git a/themes/coo/layout/_partial/structured-data.ejs b/themes/coo/layout/_partial/structured-data.ejs new file mode 100644 index 0000000..e96c292 --- /dev/null +++ b/themes/coo/layout/_partial/structured-data.ejs @@ -0,0 +1,217 @@ + \ No newline at end of file diff --git a/themes/coo/scripts/seo-enhanced.js b/themes/coo/scripts/seo-enhanced.js new file mode 100644 index 0000000..7f7110a --- /dev/null +++ b/themes/coo/scripts/seo-enhanced.js @@ -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 = /]*>/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; +});