{"id":14971161,"url":"https://github.com/freb97/nuxt-strapi-blocks-renderer","last_synced_at":"2025-04-07T15:06:23.359Z","repository":{"id":214098683,"uuid":"735677692","full_name":"freb97/nuxt-strapi-blocks-renderer","owner":"freb97","description":"Nuxt 3 module for rendering text with the new Blocks rich text editor from Strapi CMS","archived":false,"fork":false,"pushed_at":"2025-04-07T13:28:23.000Z","size":474,"stargazers_count":41,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-07T14:32:06.083Z","etag":null,"topics":["blocks","json","nuxt","nuxt-module","nuxt3","nuxtjs","strapi","strapi-cms"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/nuxt-strapi-blocks-renderer","language":"TypeScript","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/freb97.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-12-25T19:37:41.000Z","updated_at":"2025-04-02T10:12:42.000Z","dependencies_parsed_at":"2024-01-14T08:49:44.866Z","dependency_job_id":"96244d5b-b0ba-47de-bd99-3c010a0d1d26","html_url":"https://github.com/freb97/nuxt-strapi-blocks-renderer","commit_stats":{"total_commits":57,"total_committers":7,"mean_commits":8.142857142857142,"dds":"0.26315789473684215","last_synced_commit":"0b52e5c027bb2233c3c2889660c178dcb226e166"},"previous_names":["freb97/nuxt-strapi-blocks-renderer"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freb97%2Fnuxt-strapi-blocks-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freb97%2Fnuxt-strapi-blocks-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freb97%2Fnuxt-strapi-blocks-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freb97%2Fnuxt-strapi-blocks-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freb97","download_url":"https://codeload.github.com/freb97/nuxt-strapi-blocks-renderer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247672692,"owners_count":20976994,"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":["blocks","json","nuxt","nuxt-module","nuxt3","nuxtjs","strapi","strapi-cms"],"created_at":"2024-09-24T13:44:47.919Z","updated_at":"2025-04-07T15:06:23.332Z","avatar_url":"https://github.com/freb97.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nuxt Strapi Blocks Renderer\n\n[![Github Actions][github-actions-src]][github-actions-href]\n[![NPM version][npm-version-src]][npm-version-href]\n[![NPM downloads][npm-downloads-src]][npm-downloads-href]\n[![License][license-src]][license-href]\n\nA fully customizable Nuxt 3 module for rendering text with the new Blocks rich text editor element from Strapi CMS.\n\nThe implementation is based on Strapi's [Blocks React Renderer](https://github.com/strapi/blocks-react-renderer/).\n\n- ✨ [Release notes](/CHANGELOG.md)\n- 🏀 [Online stackblitz playground](https://stackblitz.com/github/freb97/nuxt-strapi-blocks-renderer?file=playground%2Fbasic%2Fpages%2Findex.vue)\n\n## Installation\n\n1. Install the Blocks renderer:\n\n    ```bash\n    npm install nuxt-strapi-blocks-renderer\n    ```\n\n2. Add the module to `nuxt.config.{ts|js}`:\n\n    ```typescript\n    modules: ['nuxt-strapi-blocks-renderer']\n    ```\n\n## Usage\n\nTo render text, use the `StrapiBlocksText` component:\n\n```vue\n\u003cStrapiBlocksText :nodes=\"blockNodes\" /\u003e\n```\n\nIn this example, the `blockNodes` are taken from the JSON response which Strapi provides when using the Blocks rich\ntext editor element:\n\n```vue\n\u003cscript setup lang=\"ts\"\u003e\n    import type { BlockNode } from '#strapi-blocks-renderer/types';\n    import type { Restaurant } from '~/types';\n\n    const route = useRoute();\n    const { findOne } = useStrapi();\n\n    // Fetch restaurants data from Strapi\n    const response = await findOne\u003cRestaurant\u003e('restaurants', route.params.id);\n    \n    // Obtain blocks text nodes from description field\n    const blockNodes: BlockNode[] = response.data.attributes.description;\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n    \u003c!-- Render blocks text --\u003e\n    \u003cStrapiBlocksText :nodes=\"blockNodes\" /\u003e\n\u003c/template\u003e\n```\n\nTo use the `useStrapi` composable, install the [Strapi Nuxt module](https://strapi.nuxtjs.org/).\n\n### Advanced Usage\n\nIn situations where your project requires specific styling or behavior for certain HTML tags such as `\u003ca\u003e`, `\u003cp\u003e`,\nand others, you can override the default rendering components used by the Nuxt Strapi Blocks Renderer.\nThis flexibility allows you to tailor the rendering to align with your project's unique design and functional needs.\n\n#### Global Component Registration\n\nFirst, ensure that your components are globally registered in your Nuxt app.\nThis step is crucial for your custom components to be recognized and used by the renderer.\n\nIn your Nuxt configuration (`nuxt.config.{js|ts}`), add:\n\n```typescript\ncomponents: {\n    dirs: [\n        {\n            path: '~/components',\n        },\n    ],\n    global: true,\n},\n```\n\n#### Customizing the Paragraph Tag\n\nTo customize the rendering of the paragraph (`\u003cp\u003e`) tag, you need to create a corresponding Vue component.\nThe name of the component follows a predefined pattern: `'StrapiBlocksText' + [NodeName] + 'Node.vue'`.\nTo override the default paragraph tag, we create a file called `StrapiBlocksTextParagraphNode.vue`.\n\n```vue\n\u003c!-- components/StrapiBlocksTextParagraphNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cp class=\"my-custom-class-for-p\"\u003e\n        \u003cslot /\u003e\n    \u003c/p\u003e\n\u003c/template\u003e\n```\n\nThis component assigns a custom class `my-custom-class-for-p` to the paragraph tag, which can be styled as needed.\n\nThe prefix for the custom components can be adjusted in your `nuxt.config.{js|ts}`:\n\n```typescript\nmodules: ['nuxt-strapi-blocks-renderer'],\nstrapiBlocksRenderer: {\n    prefix: 'MyCustomPrefix'\n    blocksPrefix: 'MyCustomBlocksPrefix',\n},\n```\n\nWith this configuration, the `StrapiBlocksText` component becomes `MyCustomPrefixStrapiBlocksText` and the custom\nparagraph node component would be named `MyCustomBlocksPrefixParagraphNode`.\n\n#### Other Custom Tags\n\nYou can apply similar customizations to all other HTML tags used by the renderer:\n\n\u003cdetails\u003e\n\u003csummary\u003eHeadings\u003c/summary\u003e\n\nCustom heading tags (`\u003ch1\u003e`, `\u003ch2\u003e`, `\u003ch3\u003e`, etc.):\n\n```vue\n\u003c!-- components/StrapiBlocksTextHeading1Node.vue --\u003e\n\u003ctemplate\u003e\n    \u003ch1 class=\"my-custom-class-for-h1\"\u003e\n        \u003cslot /\u003e\n    \u003c/h1\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextHeading2Node.vue --\u003e\n\u003ctemplate\u003e\n    \u003ch2 class=\"my-custom-class-for-h2\"\u003e\n        \u003cslot /\u003e\n    \u003c/h2\u003e\n\u003c/template\u003e\n```\n\nThis pattern also extends to the `h3`, `h4`, `h5` and `h6` tags.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eLists\u003c/summary\u003e\n\nCustom list tags (`\u003col\u003e`, `\u003cul\u003e` and `\u003cli\u003e`):\n\n```vue\n\u003c!-- components/StrapiBlocksTextOrderedListNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003col class=\"my-custom-class-for-ol\"\u003e\n        \u003cslot /\u003e\n    \u003c/ol\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextUnorderedListNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cul class=\"my-custom-class-for-ul\"\u003e\n        \u003cslot /\u003e\n    \u003c/ul\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextListItemInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cli class=\"my-custom-class-for-li\"\u003e\n        \u003cslot /\u003e\n    \u003c/li\u003e\n\u003c/template\u003e\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eBlockquotes and Codes\u003c/summary\u003e\n\nCustom blockquote and code tags (`\u003cblockquote\u003e`, `\u003cpre\u003e`):\n\n```vue\n\u003c!-- components/StrapiBlocksTextQuoteNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cblockquote class=\"my-custom-class-for-blockquote\"\u003e\n        \u003cslot /\u003e\n    \u003c/blockquote\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextCodeNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cpre class=\"my-custom-class-for-pre\"\u003e\u003cslot /\u003e\u003c/pre\u003e\n\u003c/template\u003e\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eInline text nodes\u003c/summary\u003e\n\nCustom inline text nodes (`\u003cstrong\u003e`, `\u003cem\u003e`, `\u003cu\u003e`, `\u003cdel\u003e`, `\u003ccode\u003e`):\n\n```vue\n\u003c!-- components/StrapiBlocksTextBoldInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cstrong class=\"my-custom-class-for-strong\"\u003e\n        \u003cslot /\u003e\n    \u003c/strong\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextItalicInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cem class=\"my-custom-class-for-em\"\u003e\n        \u003cslot /\u003e\n    \u003c/em\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextUnderlineInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cu class=\"my-custom-class-for-u\"\u003e\n        \u003cslot /\u003e\n    \u003c/u\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextStrikethroughInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003cdel class=\"my-custom-class-for-del\"\u003e\n        \u003cslot /\u003e\n    \u003c/del\u003e\n\u003c/template\u003e\n\n\u003c!-- components/StrapiBlocksTextCodeInlineNode.vue --\u003e\n\u003ctemplate\u003e\n    \u003ccode class=\"my-custom-class-for-code\"\u003e\n        \u003cslot /\u003e\n    \u003c/code\u003e\n\u003c/template\u003e\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eLinks\u003c/summary\u003e\n\nCustom link tag (`\u003ca\u003e`):\n\n```vue\n\u003c!-- components/StrapiBlocksTextLinkInlineNode.vue --\u003e\n\u003cscript setup lang=\"ts\"\u003e\n    const props = defineProps\u003c{\n        url: string;\n    }\u003e();\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n    \u003ca :href=\"props.url\" class=\"my-custom-class-for-a\"\u003e\n        \u003cslot /\u003e\n    \u003c/a\u003e\n\u003c/template\u003e\n```\n\nWhen rendering a link tag, the url gets passed as the `url` component property.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eImages\u003c/summary\u003e\n\nCustom image tag (`\u003cimg\u003e`):\n\n```vue\n\u003c!-- components/StrapiBlocksTextImageNode.vue --\u003e\n\u003cscript setup lang=\"ts\"\u003e\n    const props = defineProps\u003c{\n        image: any;\n    }\u003e();\n\u003c/script\u003e\n\n\u003ctemplate\u003e\n    \u003cimg\n        class=\"my-custom-class-for-img\"\n        :src=\"props.image.url\"\n        :alt=\"props.image.alternativeText\"\n        :width=\"props.image.width\"\n        :height=\"props.image.height\"\n    \u003e\n\u003c/template\u003e\n```\n\nWhen rendering an image tag, the image object gets passed as the `image` component property.\nYou can also use different image components here, i.e. `NuxtImg` or others.\n\u003c/details\u003e\n\n## Development\n\n### Dependencies\n\nTo install the dependencies, run the `install` command:\n\n```bash\nnpm install\n```\n\nThe project requires Node.js and NPM to run.\nYou can either install these manually on your system or if you have the nix package manager installed, use the\nprovided nix-shell with the following command:\n\n```bash\nnix-shell\n```\n\nThis will automatically install the needed software and start up a shell.\n\n### Type stubs\n\nTo generate the type stubs for the nuxt module, run the `dev:prepare` command:\n\n```bash\nnpm run dev:prepare\n```\n\n### Development server\n\nTo start the development server with the provided text components, run the `dev` command:\n\n```bash\nnpm run dev\n```\n\nThis will boot up the playground with the default text components.\nTo start the development server using custom text components, overriding the provided components,\nuse the `dev:custom` command:\n\n```bash\nnpm run dev:custom\n```\n\n### Quality\n\n#### Linter\n\nTo run ESLint, use the following command:\n\n```bash\nnpm run lint:es\n```\n\n#### Type checks\n\nTo run the TypeScript type checks, use the following command:\n\n```bash\nnpm run lint:types\n```\n\n#### Unit Tests\n\nTo run the Vitest unit tests, run the following command:\n\n```bash\nnpm run test\n````\n\n### Build\n\nTo build the module, first install all dependencies and [generate the type stubs](#type-stubs).\nThen run the build script:\n\n```bash\nnpm run build\n```\n\nThe module files will be output to the `dist` folder.\n\n### Release\n\nTo release a new version of the strapi blocks renderer nuxt module, take the following steps:\n\n1. Increment version number in the `package.json` file\n2. Add changelog entry for the new version number\n3. Run linters and unit tests\n4. Build the nuxt module\n \n   ```bash\n   npm run build\n   ```\n\n5. Log in to NPM using your access token\n6. Run the `release` command\n\n   ```bash\n   npm run release\n   ```\n\n[github-actions-src]: https://github.com/freb97/nuxt-strapi-blocks-renderer/actions/workflows/ci.yml/badge.svg\n[github-actions-href]: https://github.com/freb97/nuxt-strapi-blocks-renderer/actions\n\n[npm-version-src]: https://img.shields.io/npm/v/nuxt-strapi-blocks-renderer/latest.svg?style=flat\u0026colorA=18181B\u0026colorB=31C553\n[npm-version-href]: https://npmjs.com/package/nuxt-strapi-blocks-renderer\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-strapi-blocks-renderer.svg?style=flat\u0026colorA=18181B\u0026colorB=31C553\n[npm-downloads-href]: https://npmjs.com/package/nuxt-strapi-blocks-renderer\n\n[license-src]: https://img.shields.io/github/license/freb97/nuxt-strapi-blocks-renderer.svg?style=flat\u0026colorA=18181B\u0026colorB=31C553\n[license-href]: https://github.com/freb97/nuxt-strapi-blocks-renderer/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreb97%2Fnuxt-strapi-blocks-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreb97%2Fnuxt-strapi-blocks-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreb97%2Fnuxt-strapi-blocks-renderer/lists"}