English CMS: Use Json-LD effectivelystampToDateFilter, bring readability to timestamps

As an experienced website operations expert, I know that in today's digital marketing era, website content not only needs to attract users, but also to 'please' search engines.AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language. With its high efficiency, flexibility, and SEO-friendly features, it has become a powerful assistant for many small and medium-sized enterprises and content operation teams.Among the many strategies to improve SEO performance, structured data (Json-LD) plays a crucial role. It helps search engines understand web content more accurately, thereby improving search rankings and display effects.

When configuring JSON-LD structured data, we often encounter situations where we need to handle time information, such as the publication date or update date of the article.These times are typically stored in the database in the form of timestamps (Timestamp), while the Json-LD standard requires dates to be presented in a human-readable and machine-friendly specific format.stampToDate过滤器就派上了大用场,它能轻松地将原始时间戳转换为符合Json-LD规范的日期格式。

Understanding the Integration of Json-LD and AnQi CMS

Json-LD (JSON for Linking Data) is a lightweight linking data format that allows webmasters to embed structured data directly into HTML pages, enabling search engines to understand the relationships and properties of various entities on the page (such as articles, products, events, etc.).The Anqi CMS has taken SEO optimization into full consideration since its design, therefore it naturally supports structured data.The system will automatically generate basic Json-LD for your content in the background, saving you the trouble of manual writing.

However, for some personalized needs, such as our desire to display specific author information, custom image lists, or, as we discuss today, precise control over the date and time format, Anqi CMS provides极高的flexibility. You can do this by using{% jsonLd %}...{% endjsonLd %}Tags, to inject or override the default generated Json-LD content.In this custom block, you can define the structured data fields you need as if you were writing regular JSON, and the Anke CMS will intelligently merge these custom contents with the default Json-LD generated by the system.

Timestamp and readable date: Why is formatting so important?

In the article of Anqi CMS, whether it isCreatedTime(creation time) orUpdatedTime(Updated time), this data is stored in the background in the form of a 10-digit timestamp.The timestamp essentially is a sequence of numbers, representing the number of seconds from a fixed point in time (usually the Unix epoch, January 1, 1970, 00:00:00 UTC) to a specific time.This format is very efficient for database and program processing, but it is not intuitive for human reading and search engine parsing.

In JSON-LD and other structured data, date and time information must follow the ISO 8601 standard, for exampleYYYY-MM-DDTHH:MM:SSZ.This unified format ensures consistency in the understanding of date and time across different systems and regions, avoiding ambiguity.For search engines, precise and standardized date information helps them judge the 'freshness', relevance, and position of content on the timeline, which is particularly crucial for time-sensitive content such as news, blogs, and events.Therefore, converting timestamps into readable standardized dates is an essential step to enhance content value and SEO performance.

stampToDateFilter: The date formatting tool of Anqi CMS

To solve the problem of converting timestamps to readable dates, Anqi CMS has built-in a very practicalstampToDateFilter. Its usage is simple and clear, able to directly format a 10-digit timestamp into any date and time format you need.

stampToDateThe basic syntax of the filter is: {{stampToDate(时间戳, "格式")}}.

Here it is especially important to pay attention to the “format” part. The template engine of Anqi CMS is based on Go language, and its date formatting method also follows the unique style of Go language, that is, through a specific reference date——2006-01-02 15:04:05.999999999 -0700 MSTDefine the output format. You do not need to remember this long reference date, just remember the meanings of each part of it:

  • 2006Represents the year
  • 01represents the month
  • 02represents the date
  • 15Represents the hour in 24-hour format
  • 04Represents minutes
  • 05Represents seconds
  • MSTorZ07:00Represents timezone information (often used in Json-LD)Z07:00Indicates the UTC time offset)

By combining these numbers, you can flexibly create various date formats. For example:

  • "2006-01-02"It will output年-月-日such as2023-10-26
  • "2006年01月02日"It will output2023年10月26日
  • "2006/01/02 15:04"It will output年/月/日 时:分such as2023/10/26 10:30
  • And for Json-LD, we often need ISO 8601 format, which can be used like this:"2006-01-02T15:04:05Z07:00"It will output something similar,2023-10-26T10:30:00+08:00such a standardized date and time.

The English translation of 'auto' is 'English'.dateThe English translation of 'auto' is 'English'.dateThe English translation of 'auto' is 'English'.time.TimeType object, not a raw timestamp. Therefore, when processing 10-digit timestamps directly returned by the database,stampToDateis a more direct and convenient choice.

integrated in Json-LDstampToDate:实战范例

现在,我们来看一个具体的例子,如何在文章(Article)类型的Json-LD中,利用`stampTo