{"id":19106531,"url":"https://github.com/web-alchemy/eleventy-plugin-content-dates","last_synced_at":"2025-04-30T18:01:38.154Z","repository":{"id":165933184,"uuid":"641331669","full_name":"web-alchemy/eleventy-plugin-content-dates","owner":"web-alchemy","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-18T07:14:14.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T08:10:17.585Z","etag":null,"topics":["dates","eleventy","eleventy-plugin","git"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/web-alchemy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-16T08:53:22.000Z","updated_at":"2024-08-16T08:01:46.000Z","dependencies_parsed_at":"2024-08-16T06:25:23.614Z","dependency_job_id":"966bb2ec-6b91-4ed4-a5ac-a73b489d2fe6","html_url":"https://github.com/web-alchemy/eleventy-plugin-content-dates","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-alchemy%2Feleventy-plugin-content-dates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-alchemy%2Feleventy-plugin-content-dates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-alchemy%2Feleventy-plugin-content-dates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/web-alchemy%2Feleventy-plugin-content-dates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/web-alchemy","download_url":"https://codeload.github.com/web-alchemy/eleventy-plugin-content-dates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758162,"owners_count":21638988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dates","eleventy","eleventy-plugin","git"],"created_at":"2024-11-09T04:08:35.453Z","updated_at":"2025-04-30T18:01:38.049Z","avatar_url":"https://github.com/web-alchemy.png","language":"JavaScript","readme":"# Eleventy plugin for content dates\n\nStatic site generator [Eleventy](https://www.11ty.dev/docs/dates/) uses a special data field `date` with predefined values `Created`, `Last Modified`, `git Created`, `git Last Modified` to sort collections and show post date.\n\nBut there are two problems here:\n- it is not possible to use several fields at the same time, for example, for the creation date and for the modification date,\n- the date is calculated for one file, but you can have a whole folder for an article with pictures, fonts and other resources. Their update should also be considered as a modification of the article.\n\nThis plugin solves this problems.\n\n## Installation\n\n```bash\nnpm install @web-alchemy/eleventy-plugin-content-dates\n```\n\n## Configuration\n\n```javascript\nconst { eleventyPluginContentDates } = require('@web-alchemy/eleventy-plugin-content-dates');\n\nmodule.exports = function(eleventyConfig) {\n  eleventyConfig.addPlugin(eleventyPluginContentDates);\n}\n```\n\nBy default, dates are calculated for a file with the path `data.page.inputPath`. But you can change the path to the entity for which you need to calculate dates, for example, for a folder. Sometimes you need to calculate dates for folders, as they may contain other resources, for example, pictures. You can use the `getContentFolderPath` function from the plugin or write your own.\n\n```javascript\nconst { eleventyPluginContentDates, getContentFolderPath } = require('@web-alchemy/eleventy-plugin-content-dates');\n\nmodule.exports = function(eleventyConfig) {\n  eleventyConfig.addPlugin(eleventyPluginContentDates, {\n    // this is default\n    getContentPath: (data) =\u003e {\n      return data.page.inputPath;\n    }\n    \n    // you can compute dates for folders using library function `getContentFolderPath`\n    getContentPath: getContentFolderPath\n    \n    // or write your own logic for getting path\n    getContentPath: async (data) =\u003e {\n      // `data` - is Eleventy data\n      // function can be async\n    }\n  });\n}\n```\n\nBy default, library uses are async functions from modules `node:fs` and `node:child_process`. You can use sync version of this functions;\n\n```javascript\nconst { eleventyPluginContentDates, MODE } = require('@web-alchemy/eleventy-plugin-content-dates');\n\nmodule.exports = function(eleventyConfig) {\n  eleventyConfig.addPlugin(eleventyPluginContentDates, {\n    mode: MODE.SYNC\n  });\n}\n```\n\n## Usage\n\nThe plugin uses specials values for date fields:\n\n- `Date. FS. Created` - the date of creation file received from the file system\n- `Date. FS. Last Modified` - the date of modification file received from the file system\n- `Date. Git. Created` - the date of creation file received from the git\n- `Date. Git. Last Modified` - the date of modification file received from the git\n\nUsing in frontmatter:\n\n```nunjucks\n---\ncreatedAt: 'Date. Git. Created'\nupdatedAt: 'Date. Git. Last Modified'\n---\n\n\u003ctime datetime=\"{{ createdAt.toISOString()}}\"\u003e\n  {{ createdAt.toLocaleDateString() }}\n\u003c/time\u003e\n\n\u003ctime datetime=\"{{ updatedAt.toISOString()}}\"\u003e\n  {{ updatedAt.toLocaleDateString() }}\n\u003c/time\u003e\n```\n\nUsing in `11tydata`-files:\n\n```javascript\nconst { TIMESTAMPS } = require('@web-alchemy/eleventy-plugin-content-dates');\n\nmodule.exports = {\n  createdAtWithFS: TIMESTAMPS.FS_CREATED,\n  updatedAtWithFS: TIMESTAMPS.FS_LAST_MODIFIED,\n  createdAtWithGit: TIMESTAMPS.GIT_CREATED,\n  updatedAtWithGit: TIMESTAMPS.GIT_LAST_MODIFIED,\n}\n```\n\n## Low level usage example\n\nYou can use `@web-alchemy/eleventy-plugin-content-dates` as a library without registering the plugin:\n\n```javascript\n// index.11tydata.js\nconst path = require('node:path');\nconst { TIMESTAMPS, MODE, computeDate } = require('@web-alchemy/eleventy-plugin-content-dates');\n\nmodule.exports = {\n  eleventyComputed: {\n    yourCustomDateField: async function(data) {\n      return await computeDate({\n        strategy: TIMESTAMPS.GIT_LAST_MODIFIED,\n        mode: MODE.ASYNC,\n        contentPath: path.dirname(data.page.inputPath),\n      })\n    },\n    \n    yourAnotherCustomDateField: function(data) {      \n      return computeDate({\n        strategy: TIMESTAMPS.FS_CREATED,\n        mode: MODE.SYNC,\n        contentPath: data.page.inputPath,\n      })\n    },\n  }\n}\n```\n\n## Caveats of use on CI/CD\n\nMany CI/CD tools, such as [Github Actions Checkout](https://github.com/actions/checkout), by default does a shallow clone and dates may be incorrect.\n\nSolutions:\n\n- Make deep clone with `fetch-depth: '0'`:\n  ```yaml\n    - name: Checkout\n      uses: actions/checkout@v4\n      with:\n        fetch-depth: '0'\n  ```\n  This is also helpful, if you use git creation dates. But with this method, all branches and tags are pulled out, not just the history of one branch.\n- Write your own git commands. Just example:\n  ```yaml\n  - name: Checkout\n    run: |\n      git clone --depth 1 \u003cREPO\u003e .\n      git fetch --unshallow\n  ```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-alchemy%2Feleventy-plugin-content-dates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweb-alchemy%2Feleventy-plugin-content-dates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-alchemy%2Feleventy-plugin-content-dates/lists"}