Hacker News 中文摘要

RSS订阅

JSON-LD 个人网站应用详解 -- JSON-LD Explained for Personal Websites

文章摘要

JSON-LD是一种为网页添加结构化数据的格式,能帮助网络爬虫理解网站语义,从而获得更丰富的链接预览并可能提升搜索排名。文章介绍了其基本原理,即在页面头部添加特定脚本标签,并解释了各组成部分的作用。

文章总结

好的,这是根据您的要求,对原文主要内容进行的中文重述,保留了关键细节,并删减了与主题无关的个人经历描述。


标题:为个人网站解释 JSON-LD

核心内容:

JSON-LD(JSON 链接数据)是一种为网页添加结构化数据的格式。它能帮助网络爬虫理解你网站的语义结构,从而获得更丰富的链接预览,甚至可能提升搜索排名。

JSON-LD 基础

要添加 JSON-LD,你需要在网页的 <head> 部分插入如下代码:

```html

```

  • <script type="application/ld+json">:声明一个MIME类型为 application/ld+json 的脚本。浏览器不会执行它,但像Googlebot这样的爬虫会专门解析其内容。
  • "@context": "https://schema.org":定义了JSON-LD遵循的数据结构标准。网络爬虫都基于 Schema.org 来理解JSON中的键值对。
  • "@graph":一个JSON-LD文档可以被看作一个带标签的有向图,存储在 @graph 下。图包含多个节点,节点之间通过有向弧连接。
    • 节点属性
      • @type:描述节点的类型,例如 WebSiteSoftwareApplication
      • @id:节点的唯一标识符,通常是一个带有唯一哈希值的URL。
      • 属性:描述节点特征的键值对。

网络爬虫可以跨页面合并具有相同 @id 的节点属性。但只读取单个页面的爬虫(如LLM)则不会合并。因此,最佳实践是让 @id 采用“URL + # + 唯一标识”的格式。

个人网站应包含的节点类型

以下是为个人网站带来显著SEO影响的节点类型,并附有可直接复制修改的JSON-LD示例。

1. WebSite(网站)

描述网站本身的元数据,例如名称、描述、语言等。首页应包含完整版本,其他页面可以使用精简版。

完整版示例(用于首页): json { "@type": "WebSite", "@id": "https://你的网站.com/#website", "url": "https://你的网站.com/", "name": "你的名字或网站名", "alternateName": ["别名1", "别名2"], "description": "网站描述", "inLanguage": "zh-CN", "publisher": { "@id": "https://你的网站.com/#person" }, "image": { "@type": "ImageObject", "@id": "https://你的网站.com/#website-image", "url": "https://你的网站.com/logo.png", "caption": "网站Logo" } }

精简版示例(用于其他页面): json { "@type": "WebSite", "@id": "https://你的网站.com/#website", "url": "https://你的网站.com/", "name": "你的名字或网站名" }

2. WebPage(网页)

描述当前页面本身(HTML)。它有更具体的子类型,如 ProfilePageCollectionPage

json { "@type": "WebPage", "@id": "https://你的网站.com/某页面/#webpage", "url": "https://你的网站.com/某页面/", "isPartOf": { "@id": "https://你的网站.com/#website" }, "name": "页面标题", "inLanguage": "zh-CN", "breadcrumb": { "@id": "https://你的网站.com/某页面/#breadcrumb" } }

3. Person(个人)

描述你是谁。Google将其用作内容质量指标,LLM爬虫也用它来决定引用谁。建议在所有页面上都包含此节点。

json { "@type": "Person", "@id": "https://你的网站.com/#person", "url": "https://你的网站.com/", "name": "你的全名", "givenName": "名", "familyName": "姓", "description": "详细描述", "jobTitle": "你的职位", "knowsLanguage": "zh-CN", "image": { "@type": "ImageObject", "@id": "https://你的网站.com/#person-image", "url": "https://你的网站.com/你的照片.png", "caption": "你的名字" }, "sameAs": [ "https://github.com/你的用户名", "https://www.linkedin.com/in/你的用户名" // 其他社交或专业平台链接 ] } 重要属性说明: - url:指向你的首页。 - name, givenName, familyName:清晰描述你的姓名。 - image:你的照片或关联Logo。 - sameAs:用于消除歧义,告知爬虫你的其他个人资料页面,帮助构建知识图谱。

4. ProfilePage(个人资料页)

描述网站上关于某个人的页面,例如“关于我”页面。使用 mainEntity 链接到 Person 节点。

json { "@type": "ProfilePage", "@id": "https://你的网站.com/#webpage", "url": "https://你的网站.com/", "isPartOf": { "@id": "https://你的网站.com/#website" }, "name": "关于 [你的名字]", "inLanguage": "zh-CN", "mainEntity": { "@id": "https://你的网站.com/#person" } }

5. SoftwareApplication(软件应用)

用于展示你开发的软件项目。

json { "@type": "SoftwareApplication", "@id": "https://你的网站.com/#project-项目名", "url": "https://项目部署地址.com/", "name": "项目名称", "description": "项目描述", "applicationCategory": "MultimediaApplication", "operatingSystem": "All", "creator": { "@id": "https://你的网站.com/#person" }, "sameAs": ["https://github.com/你的用户名/项目仓库"], "offers": { "@type": "Offer", "price": 0, "priceCurrency": "CNY" } } - url 指向项目部署地址,sameAs 用于关联其他页面(如源码仓库)。 - 即使是开源免费项目,也应包含 offers 并将价格设为0。

6. BreadcrumbList(面包屑导航)

描述页面的分类路径,有助于搜索引擎更准确地显示页面路径。除首页外,其他页面都应包含。

json { "@type": "BreadcrumbList", "@id": "https://你的网站.com/某页面/#breadcrumb", "itemListElement": [ { "@type": "ListItem", "item": "https://你的网站.com/", "position": 1, "name": "首页" }, { "@type": "ListItem", "item": "https://你的网站.com/分类/", "position": 2, "name": "分类名" }, { "@type": "ListItem", "item": "https://你的网站.com/分类/文章/", "position": 3, "name": "文章标题" } ] }

7. CollectionPage(集合页)

WebPage 的子类型,用于主要包含列表的页面,如博客列表页、链接汇总页。

json { "@type": "CollectionPage", "@id": "https://你的网站.com/列表页/#webpage", "url": "https://你的网站.com/列表页/", "isPartOf": { "@id": "https://你的网站.com/#website" }, "name": "页面标题", "description": "页面描述", "inLanguage": "zh-CN", "about": { "@id": "https://你的网站.com/#person" }, "breadcrumb": { "@id": "https://你的网站.com/列表页/#breadcrumb" } }

8. Blog(博客)

添加到博客首页,作为 WebSite 和单篇博文之间的桥梁。

json { "@type": "Blog", "@id": "https://你的网站.com/blog/#blog", "isPartOf": { "@id": "https://你的网站.com/#website" }, "mainEntityOfPage": { "@id": "https://你的网站.com/blog/#webpage" }, "name": "你的博客名称", "description": "博客描述", "inLanguage": "zh-CN", "publisher": { "@id": "https://你的网站.com/#person" }, "license": "https://creativecommons.org/licenses/by/4.0/" } 对于个人网站,publisher 属性可以设置为 Person 类型,这比 Organization 更准确。

9. BlogPosting(博文)

用于每篇发布的博文,提供更丰富的信息,以获得更准确的搜索结果展示。

json { "@type": "BlogPosting", "@id": "https://你的网站.com/blog/文章名/#blogposting", "url": "https://你的网站.com/blog/文章名/", "mainEntityOfPage": { "@id": "https://你的网站.com/blog/文章名/#webpage" }, "isPartOf": { "@id": "https://你的网站.com/blog/#blog" }, "headline": "文章标题", "description": "文章描述", "keywords": "关键词1, 关键词2", "inLanguage": "zh-CN", "datePublished": "2024-01-01T00:00:00.000Z", "dateModified": "2024-01-02T00:00:00.000Z", "author": { "@id": "https://你的网站.com/#person" }, "publisher": { "@id": "https://你的网站.com/#person" }, "image": { "@type": "ImageObject", "@id": "https://你的网站.com/blog/文章名/#blogposting-image", "url": "https://你的网站.com/og/文章名.png", "width": 1200, "height": 630 }, "license": "https://creativecommons.org/licenses/by/4.0/" } 对于个人网站,authorpublisher 指向同一个 Person 节点是合理的。image 应与文章用于链接预览的OG图片一致。

总结

以上是个人网站所需的全部JSON-LD节点。即使你的网站是静态的,没有构建步骤,也至少可以在首页添加 WebSiteProfilePagePerson 这三个节点来获益。

评论总结

根据评论内容,主要观点和论据如下:

观点一:JSON-LD存在信息重复问题(认可度较高) - 评论1指出,使用常见解析器时需在HTML和JSON-LD中重复表述信息,而RDFa本可避免此问题("A bit disappointing that... you have to say everything twice")。 - 评论2批评语义HTML已存在,却仍需在脚本标签中用JSON-LD重新表达语义("we need to yet again re-express the semantic meaning... in bespoke weird JSON")。

观点二:JSON-LD实用且被搜索引擎采用(认可度中等) - 评论4认为JSON-LD易于使用且被搜索引擎实际应用,信息重复可接受("JSON-LD is nice because it’s easy and it is actually used by search engines... I am ok with a little duplication")。 - 评论3肯定文章对SEO的实用性,并澄清了对type字段的误解("Super useful article, wish that had existed in my seo days")。

观点三:对搜索引擎优化效果的质疑(认可度较低) - 评论5指出,Google已转向LLM生成内容,结构化数据对排名提升作用有限("Google has nowadays switched to giving people lengthy LLM-generated versions... de-prioritizes all of that")。 - 评论6质疑这些属性是否真正帮助搜索可见性,还是仅让用户留在搜索页("Do these attributes actually help with search engine visibility or do they just make it easier for search engines to keep users from leaving the search page?")。