{"id":15022971,"url":"https://github.com/nhoizey/eleventy-plugin-link_to","last_synced_at":"2025-07-19T16:13:32.719Z","repository":{"id":48329689,"uuid":"305734069","full_name":"nhoizey/eleventy-plugin-link_to","owner":"nhoizey","description":"A Nunjucks tag to link to another internal content in Eleventy with its slug.","archived":false,"fork":false,"pushed_at":"2024-01-30T13:39:52.000Z","size":104,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-08T17:12:08.362Z","etag":null,"topics":["eleventy","eleventy-plugin","link","nunjucks-tag","slug"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhoizey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-10-20T14:25:48.000Z","updated_at":"2024-08-14T20:03:14.000Z","dependencies_parsed_at":"2024-09-22T16:00:31.731Z","dependency_job_id":null,"html_url":"https://github.com/nhoizey/eleventy-plugin-link_to","commit_stats":{"total_commits":46,"total_committers":4,"mean_commits":11.5,"dds":"0.21739130434782605","last_synced_commit":"f4c43831aa2087357c7fc387e5154770af5f5340"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhoizey%2Feleventy-plugin-link_to","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhoizey%2Feleventy-plugin-link_to/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhoizey%2Feleventy-plugin-link_to/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhoizey%2Feleventy-plugin-link_to/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhoizey","download_url":"https://codeload.github.com/nhoizey/eleventy-plugin-link_to/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238053514,"owners_count":19408699,"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":["eleventy","eleventy-plugin","link","nunjucks-tag","slug"],"created_at":"2024-09-24T19:58:35.496Z","updated_at":"2025-02-10T03:31:28.070Z","avatar_url":"https://github.com/nhoizey.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `eleventy-plugin-link_to`\n\n[![npm](https://img.shields.io/npm/v/eleventy-plugin-link_to?logo=npm\u0026style=for-the-badge)](\u003c![npm](https://img.shields.io/npm/v/eleventy-plugin-link_to?logo=npm\u0026style=for-the-badge)\u003e)\n[![npm](https://img.shields.io/npm/dw/eleventy-plugin-link_to?style=for-the-badge\u0026logo=npm)](https://www.npmjs.com/package/eleventy-plugin-link_to)\n[![GitHub stars](https://img.shields.io/github/stars/nhoizey/eleventy-plugin-link_to.svg?style=for-the-badge\u0026logo=github)](https://github.com/nhoizey/eleventy-plugin-link_to/stargazers)\n[![Follow @nhoizey@mamot.fr](https://img.shields.io/mastodon/follow/000262395?domain=https%3A%2F%2Fmamot.fr\u0026style=for-the-badge\u0026logo=mastodon\u0026logoColor=white\u0026color=6364FF)](https://mamot.fr/@nhoizey)\n\nA Nunjucks tag to link to another internal content in Eleventy with its slug.\n\n# Installation\n\nThe plugin is available on npm: \u003chttps://www.npmjs.com/package/eleventy-plugin-link_to\u003e\n\nInstall it as a dev dependency in your Eleventy project:\n\n```bash\nnpm install eleventy-plugin-link_to --save-dev\n```\n\nThen add the plugin in your `.eleventy.js` configuration file and make sure Markdown is parsed with Nunjucks instead of [the default Liquid template engine](https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files):\n\n```javascript\nmodule.exports = function (eleventyConfig) {\n  eleventyConfig.addPlugin(require('eleventy-plugin-link_to'));\n  return {\n    markdownTemplateEngine: 'njk',\n  };\n};\n```\n\n# Usage\n\nThis plugin adds a Nunjucks tag you can use both in Nunjucks layouts and in Markdown content.\n\nHere's the syntax:\n\n```nunjucks\n{% link_to \"the-content-slug\" %}\n```\n\n_ℹ️ This is a [Nunjucks custom tag](https://www.11ty.dev/docs/custom-tags/), not an [Eleventy shortcode](https://www.11ty.dev/docs/shortcodes/)._\n\nLet's say you have the following contents:\n\n```\n/about.md\n/index.md\n/notes/2019/03/10/hello.md\n/notes/2020/09/05/how-many-plugins.md\n/posts/2020/09/22/hello.md\n/posts/2020/10/20/new-plugin.md\n/tag-page.njk\n```\n\n## Use the full slug\n\nYou can use `{% link_to \"new-plugin\" %}` to link to `/posts/2020/10/20/new-plugin/`.\n\n## Use the filePathStem\n\n_ℹ️ In Eleventy, [filePathStem](https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem) is \"mapped from inputPath and is useful if you’ve inherited a project that doesn’t use clean permalinks.\"_\n\nThere are two content with the same `hello` slug, so you can't use `{% link_to \"hello\" %}`.\n\nYou can use `{% link_to \"/notes/2019/03/10/hello\" %}` instead.\n\n## Use the URL\n\nYou can also use `{% link_to \"/notes/2019/03/10/hello/\" %}`, if you use Eleventy's default permalinks.\n\n## Use only a fragment of a slug/pathStem/URL\n\nYou can also use just a fragment of the content's slug (or pathStem, or URL) if you know that there is no ambiguity with another content.\n\nYou can for example use `{% link_to \"2020/09/22\" %}` because there is only one content with a slug containing `2020/09/22`.\n\n---\n\nOn [my site](https://nicolas-hoizey.com/), I can use `{% link_to \"/eleventy/\" %}` because I know the only content on my site with a slug containing `/eleventy/` is [the page of the Eleventy tag](https://nicolas-hoizey.com/tags/eleventy/), which URL is `/tags/eleventy/`.\n\n**⚠ I have to be carreful, if I add an article with the title `Eleventy` later, this link will break!**\n\nIf I use only `eleventy` without any `/`, it will currently find the page with the URL `/links/2020/03/17/eleventy-s-new-performance-leaderboard/`, which is the only content with `eleventy` in the slug (the `/tags/eleventy/` page's slug is `tag-page`, see below), and **slugs are parsed before pathStems and URLs**.\n\n# Error messages\n\nIf there is any issue finding the content you want to link to, Eleventy build log will contain one of these error messages:\n\n## `Multiple contents have the same slug '…'`\n\nIf you use a slug that is common to multiple contents.\n\nFor example, with a single `/tag-page.njk` template generating multiple pages with pagination, trying to `{% link_to \"tag-page\" %}` will give this error:\n\n```bash\n[link_to] Multiple contents have the same slug 'tag-page':\n- /tag-page\n- /tag-page\n- …\n- /tag-page\n- /tag-page\n -\u003e you can use link_to with the filePathStem or URL\n```\n\n## `Found multiple slugs containing '…', couldn't decide`\n\nIf you use a sub-string present in multiple slugs, you'll get this error:\n\n```bash\n[link_to] Found multiple slugs containing 'plugin', couldn't decide:\n- how-many-plugins\n- new-plugin\n```\n\n## `Found multiple paths or URL containing '…', couldn't decide`\n\nIf you use a sub-string present in multiple pathStem or URL, you'll get this error:\n\n```bash\n[link_to] Found multiple paths or URL containing '2020/09', couldn't decide:\n/notes/2020/09/05/how-many-plugins/\n/posts/2020/09/22/hello/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhoizey%2Feleventy-plugin-link_to","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhoizey%2Feleventy-plugin-link_to","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhoizey%2Feleventy-plugin-link_to/lists"}