Safe CMS: How to cleverly use in Json-LDstampToDateThe filter makes timestamps readable and lively

As an experienced website operation expert, I know that in today's digital marketing era, website content not only needs to attract users but also needs to 'please' search engines.AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, which has become a powerful assistant for many small and medium-sized enterprises and content operation teams with its high efficiency, flexibility, and SEO-friendly features.Among 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 an article.These times are usually 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 format.This, built-in by AnQi CMSstampToDateThe filter comes in handy, it can easily convert the original timestamp into a date format that conforms to Json-LD specifications.

Understand the integration of Json-LD and AnQi CMS

Json-LD (JSON for Linking Data) is a lightweight linking data format that allows web administrators to embed structured data directly into HTML pages, enabling search engines to understand the relationships and attributes of various entities on the page (such as articles, products, events, etc.).The AnQi CMS has always fully considered SEO optimization from its design, therefore it naturally supports structured data.The system will automatically generate the basic Json-LD for your content, saving you the trouble of manual writing.

However, for some personalized needs, such as showing specific author information, custom image lists, or as we are discussing today, precise control over the date and time format, Anqi CMS provides极高的 flexibility. You can use it in templates by{% jsonLd %}...{% endjsonLd %}Label, to inject or override the default generated Json-LD content.In this custom block, you can define the structured data fields you need as you would write normal JSON, and Anqi CMS will intelligently merge this custom content with the Json-LD generated by the system by default.

Timestamp and readable date: Why is formatting so important?

In AnQi CMS, whether it's theCreatedTime(creation time) or notUpdatedTime(Updated time), these data are stored in the background in the form of 10-digit timestamps.The timestamp is essentially a sequence of numbers that represents 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 very 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:SSZThis 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 determine the freshness, relevance, and position on the timeline of the content, which is particularly crucial for time-sensitive content such as news, blogs, and events.Therefore, converting timestamps into readable standardized dates is an indispensable step to enhance content value and SEO performance.

stampToDateFilter: Date formatting tool for AnQi CMS

To solve the problem of converting timestamps to readable dates, Anqi CMS has built-in a very practicalstampToDateA filter. Its usage is concise 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(时间戳, "格式")}}.

It should be noted that the "format" section is particularly important. The template engine of AnQi CMS is based on Go language, and its date formatting method also follows the unique style of Go language, namely 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 the various components in it:

  • 2006Represents the year
  • 01Represents the month
  • 02Represents the date
  • 15Represents the hour in 24-hour format
  • 04representing minutes
  • 05representing seconds
  • MSTorZ07:00Represents time zone information (often used in Json-LD)Z07:00Indicates 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 output.2023年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 similar2023-10-26T10:30:00+08:00Such standardized date and time.

It is easy to confuse this filter with Anqi CMSdateFilter, but please note,dateThe expected input for the filter is Go languagetime.TimeAn object type, not an original timestamp. Therefore, when processing a 10-digit timestamp directly returned by the database,stampToDateis a more direct and convenient choice.

Integration in Json-LDstampToDate: Practical Example

Now, let's look at a specific example of how to use `stampTo` in a JSON-LD of the typeArticle)