BLOG-48 SEO improvement #115

Closed
squid wants to merge 5 commits from BLOG-48_seo_improve into main
Owner

Description

Package Changes

No response

Screenshots

No response

Reference

Resolves #48

Checklist

  • A milestone is set
  • The related issuse has been linked to this branch
### Description - ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #48 ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch
squid added this to the 0.3 milestone 2025-08-05 05:45:51 +08:00
squid added 6 commits 2025-08-05 05:45:51 +08:00
Collaborator

/improve

/improve
Collaborator

PR Code Suggestions

CategorySuggestion                                                                                                                                    Impact
Possible issue
Correct structured data prop types

The datePublished and image props are typed as Date and URL respectively, but they
are likely receiving string values from the API (e.g., state.data.info.publishedTime
and state.data.info.previewImageUrl). Calling toISOString() on a string or accessing
href on a string will cause runtime errors. Ensure these props are converted to
their correct object types before use.

frontend/src/lib/post/framework/ui/StructuredData.svelte [4-23]

 const {
 	headline,
 	description,
 	datePublished,
 	image
 }: {
 	headline: string;
 	description: string;
-	datePublished: Date;
-	image: URL;
+	datePublished: string;
+	image: string;
 } = $props();
 
 const structuredData = $derived({
 	'@context': 'https://schema.org',
 	'@type': 'BlogPosting',
 	headline: headline,
 	description: description,
-	datePublished: datePublished.toISOString(),
-	image: image.href
+	datePublished: new Date(datePublished).toISOString(),
+	image: new URL(image).href
 });
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a potential runtime error where datePublished and image are typed as Date and URL but are likely passed as strings, causing toISOString() and href calls to fail. The proposed fix correctly converts these to their respective objects before use.

High
General
Limit meta description length

The meta description generated from lines.join(',') could become excessively long,
potentially leading to truncation by search engines. It's best practice to keep meta
descriptions concise, typically under 160 characters. Consider truncating the
generated description to an optimal length.

frontend/src/lib/home/framework/ui/Terminal.svelte [55-57]

+<script lang="ts">
+	// ... existing script content ...
+	const MAX_DESCRIPTION_LENGTH = 155; // Optimal length for SEO
+	const fullDescription = lines.join(',');
+	const metaDescription = fullDescription.length > MAX_DESCRIPTION_LENGTH
+		? fullDescription.substring(0, MAX_DESCRIPTION_LENGTH - 3) + '...'
+		: fullDescription;
+</script>
+
 <svelte:head>
-	<meta name="description" content="{lines.join(',')}" />
+	<meta name="description" content="{metaDescription}" />
 </svelte:head>
Suggestion importance[1-10]: 7

__

Why: The suggestion provides a valid and important improvement for SEO by ensuring the meta description does not exceed optimal lengths, preventing truncation by search engines. This enhances the quality and discoverability of the page.

Medium
## PR Code Suggestions ✨ <!-- --> <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>Possible issue</td> <td> <details><summary>Correct structured data prop types</summary> ___ **The <code>datePublished</code> and <code>image</code> props are typed as <code>Date</code> and <code>URL</code> respectively, but they <br>are likely receiving string values from the API (e.g., <code>state.data.info.publishedTime</code> <br>and <code>state.data.info.previewImageUrl</code>). Calling <code>toISOString()</code> on a string or accessing <br><code>href</code> on a string will cause runtime errors. Ensure these props are converted to <br>their correct object types before use.** [frontend/src/lib/post/framework/ui/StructuredData.svelte [4-23]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-48_seo_improve/frontend/src/lib/post/framework/ui/StructuredData.svelte#L4-L23) ```diff const { headline, description, datePublished, image }: { headline: string; description: string; - datePublished: Date; - image: URL; + datePublished: string; + image: string; } = $props(); const structuredData = $derived({ '@context': 'https://schema.org', '@type': 'BlogPosting', headline: headline, description: description, - datePublished: datePublished.toISOString(), - image: image.href + datePublished: new Date(datePublished).toISOString(), + image: new URL(image).href }); ``` <details><summary>Suggestion importance[1-10]: 9</summary> __ Why: The suggestion correctly identifies a potential runtime error where `datePublished` and `image` are typed as `Date` and `URL` but are likely passed as strings, causing `toISOString()` and `href` calls to fail. The proposed fix correctly converts these to their respective objects before use. </details></details></td><td align=center>High </td></tr><tr><td rowspan=1>General</td> <td> <details><summary>Limit meta description length</summary> ___ **The meta description generated from <code>lines.join(',')</code> could become excessively long, <br>potentially leading to truncation by search engines. It's best practice to keep meta <br>descriptions concise, typically under 160 characters. Consider truncating the <br>generated description to an optimal length.** [frontend/src/lib/home/framework/ui/Terminal.svelte [55-57]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-48_seo_improve/frontend/src/lib/home/framework/ui/Terminal.svelte#L55-L57) ```diff +<script lang="ts"> + // ... existing script content ... + const MAX_DESCRIPTION_LENGTH = 155; // Optimal length for SEO + const fullDescription = lines.join(','); + const metaDescription = fullDescription.length > MAX_DESCRIPTION_LENGTH + ? fullDescription.substring(0, MAX_DESCRIPTION_LENGTH - 3) + '...' + : fullDescription; +</script> + <svelte:head> - <meta name="description" content="{lines.join(',')}" /> + <meta name="description" content="{metaDescription}" /> </svelte:head> ``` <details><summary>Suggestion importance[1-10]: 7</summary> __ Why: The suggestion provides a valid and important improvement for SEO by ensuring the meta description does not exceed optimal lengths, preventing truncation by search engines. This enhances the quality and discoverability of the page. </details></details></td><td align=center>Medium </td></tr></tr></tbody></table>
squid added 1 commit 2025-08-05 05:47:07 +08:00
BLOG-48 style: run format
Some checks failed
PR Title Check / pr-title-check (pull_request) Failing after 17s
Frontend CI / build (push) Failing after 47s
68a175b704
squid added 1 commit 2025-08-05 05:55:11 +08:00
BLOG-48 fix: eslint
All checks were successful
PR Title Check / pr-title-check (pull_request) Successful in 16s
Frontend CI / build (push) Successful in 1m4s
c1caa10f2c
squid changed title from BLOG-48_seo_improve to BLOG-48 SEO improvement 2025-08-05 05:55:27 +08:00
squid force-pushed BLOG-48_seo_improve from c1caa10f2c to bf2ca1056b 2025-08-05 11:09:02 +08:00 Compare
squid closed this pull request 2025-08-05 11:09:42 +08:00
All checks were successful
Frontend CI / build (push) Successful in 1m10s
Required
Details
Auto Comment On PR / add_improve_comment (pull_request) Successful in 17s
PR Title Check / pr-title-check (pull_request) Successful in 17s
Required
Details

Pull request closed

Sign in to join this conversation.
No description provided.