{"_id":"@borislavhr/emdash-plugin-discord","_rev":"2-619d0885317b6b2faaf8b85fe1bb0e68","name":"@borislavhr/emdash-plugin-discord","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.0-stage":{"name":"@borislavhr/emdash-plugin-discord","version":"0.0.0-stage","_id":"@borislavhr/emdash-plugin-discord@0.0.0-stage","stub":true,"maintainers":[{"name":"borislavhr","email":"borislav.christov@gmail.com"}],"dist":{"shasum":"02a68ac370e569d1425644887c8c339c8ddce6fd","tarball":"https://registry.npmjs.org/@borislavhr/emdash-plugin-discord/-/emdash-plugin-discord-0.0.0-stage.tgz","fileCount":2,"integrity":"sha512-0/wze6mbGH8Uf4LD36zSpSvZL6n5+PuWHdV0WugggpksmtmsijnqnfJeY1abtwJDsa84hXmarIjcBnec7JFqUQ==","signatures":[{"sig":"MEUCIQC7mUQ4x74VxCZrUHE0FbYoWNr6Vsrw+v+V/YulKW7FCQIgVnk+wy6c8eU1GKSvgzP1OAoIda6QTmiv156KvJIjBXg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":355},"_npmUser":{"name":"borislavhr","email":"borislav.christov@gmail.com"},"description":"Temporary package placeholder for staged publishing","directories":{}},"1.0.0":{"_id":"@borislavhr/emdash-plugin-discord@1.0.0","bugs":"https://github.com/BorislavHr/emdash-plugins/issues","dist":{"shasum":"bcf5dd54e588bd895be747090196d80443a6e69a","tarball":"https://registry.npmjs.org/@borislavhr/emdash-plugin-discord/-/emdash-plugin-discord-1.0.0.tgz","fileCount":18,"integrity":"sha512-53fLeB+bL1LqKcW0yLCF+XISp58cXFZwtaf1N5YJrkx2B2Nmr1LQEaVPneOI7w9Sgci5gBhXdSP0bB9wagrMdQ==","signatures":[{"sig":"MEQCIAeh17ONjSEh0spHpTk56cwsU2VDs64ouSWlYXSmt97XAiBBDtmI6xwzpbYh4ylvpa0oABK1iwQMLUq+0v+5XXOtSw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEil/EXra6eQd1pmyh/8OHpe47MGTsV2pJLxQYyYyHc4AiBOX2jFsiIJ38jge2EIW+KnzYJTHWOv4zjPgFYesl0fbw=="}],"unpackedSize":54487},"name":"@borislavhr/emdash-plugin-discord","type":"module","author":{"url":"https://europe4u.online","name":"Borislav Hristov"},"engines":{"node":">=22.18"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./plugin":{"types":"./dist/plugin.d.ts","default":"./dist/plugin.js"}},"license":"MIT","scripts":{"test":"node --test \"test/*.test.ts\"","build":"tsc -p tsconfig.build.json","typecheck":"tsc -p tsconfig.json"},"version":"1.0.0","_npmUser":{"name":"borislavhr","email":"borislav.christov@gmail.com"},"homepage":"https://github.com/BorislavHr/emdash-plugins/tree/main/packages/discord#readme","keywords":["emdash","emdash-plugin","cms","discord","webhook","announcements","astro"],"repository":{"url":"git+https://github.com/BorislavHr/emdash-plugins.git","type":"git","directory":"packages/discord"},"description":"EmDash CMS plugin: a short Discord post when an entry is published for the first time, with retries, a switch and an editor panel.","directories":{},"maintainers":[{"name":"borislavhr","email":"borislav.christov@gmail.com"}],"sideEffects":false,"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"emdash":"1.5.0"},"peerDependencies":{"emdash":">=1.5.0 <2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emdash-plugin-discord_1.0.0_1795356733955_0.13777979795313944"}}},"time":{"created":"2026-11-22T14:10:37.118Z","modified":"2026-11-22T14:12:14.221Z","0.0.0-stage":"2026-11-22T14:10:37.118Z","1.0.0":"2026-11-22T14:12:14.060Z"},"description":"EmDash CMS plugin: a short Discord post when an entry is published for the first time, with retries, a switch and an editor panel.","maintainers":[{"name":"borislavhr","email":"borislav.christov@gmail.com"}],"readme":"# @borislavhr/emdash-plugin-discord\n\nA short Discord post when an entry on your EmDash site is published **for the first time**. The\npost has the entry's title as a link, its summary and its picture.\n\nIt's careful about when it posts:\n\n- Corrections, republishing, imports and copies from another site are **never** posted as new.\n- Nothing is posted until an admin switches it on.\n- Editors can keep any single entry out of Discord.\n- A failed post is tried again automatically.\n- The post can't ping anyone, even if a title contains `@everyone`.\n\n## What a post looks like\n\nOne Discord embed:\n\n- **New post** (or **New guide**, **Updated story**: your collection's name), as the small line\n  at the top\n- **The entry's title**, linking to its page\n- the summary, cut at a word to 300 characters\n- the picture: the entry's own, else its term's, else a default one\n- the first term of a taxonomy you choose (such as its category), at the bottom\n- a coloured line down the side, if you set a colour\n\n## When it posts\n\n| What happens                                                     | What the plugin does                                                                                             |\n| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| An entry is published for the first time                         | Posts it, once.                                                                                                  |\n| A published entry is edited and published again                  | Nothing. EmDash keeps the first publish date, and an entry is posted only within 24 hours of it.                 |\n| Entries are imported or copied from another site                 | Nothing: their first publish date is old.                                                                        |\n| An editor presses **Post an update** (a day after the last post) | Posts it again, labelled \"Updated …\". For a real change, such as a new section; by hand only.                    |\n| An entry published before posting was switched on                | Nothing on its own. **Post to Discord** in its panel posts it.                                                   |\n| An editor chose **Don't post this one**                          | Never posted, not even when first published, until they choose **Post it after all**.                            |\n| Discord can't be reached, or refuses                             | Tried again every 15 minutes, up to five times. Then the panel asks a person to press **Post again**.            |\n| More than 30 posts in one hour                                   | The rest wait for the next hour and go out with the retries. Guards against a stuck button or a misused account. |\n| Posting is switched off, or the webhook isn't set                | Nothing is posted.                                                                                               |\n\n## What editors see\n\nEach entry in the announced collections gets a **Discord** panel in the editor's sidebar. It\nsays, in plain words, whether the entry was posted and when, whether a post failed, or what will\nhappen when it's published. The buttons it shows depend on that state:\n\n- **Post to Discord**: an entry published before posting began.\n- **Post again**: a post that failed.\n- **Post an update**: only from a day after the last post.\n- **Don't post this one** / **Post it after all**.\n\nTo keep a new entry out of Discord: save it as a draft, choose **Don't post this one**, then\npublish.\n\nAnyone who can edit their own entries (Authors and above, permission `content:edit_own`) can use\nthe panel. The switch for the whole site, under **Plugins > Discord**, is for admins.\n\n## Requirements\n\n- **EmDash 1.5 or later** (1.x).\n- The plugin runs as a **trusted plugin** (EmDash's `plugins: []` list). It isn't a sandboxed\n  plugin and isn't in the EmDash marketplace.\n- **A Discord webhook** for the channel, in the environment variable `DISCORD_WEBHOOK_URL`.\n- **EmDash's cron** for the retries. Without it, a failed post waits for **Post again**.\n\n## Install\n\n```sh\npnpm add @borislavhr/emdash-plugin-discord\n# or: npm install @borislavhr/emdash-plugin-discord\n```\n\nAdd it to EmDash's `plugins` in `astro.config.mjs`:\n\n```js\nimport { defineConfig } from 'astro/config';\nimport emdash from 'emdash/astro';\nimport { discord } from '@borislavhr/emdash-plugin-discord';\n\nexport default defineConfig({\n  integrations: [\n    emdash({\n      // …your database, storage and other settings\n      plugins: [\n        discord({\n          collections: {\n            posts: { path: '/blog/{slug}', name: 'post' },\n            guides: { path: '/guides/{slug}', name: 'guide' },\n          },\n          summaryField: 'excerpt',\n          imageField: 'featured_image',\n          taxonomy: 'category',\n          defaultImage: '/og/default.jpg',\n          colour: '#2f6f5e',\n        }),\n      ],\n    }),\n  ],\n});\n```\n\nThe options are checked when the site builds, so a mistake (a path without `{slug}`, a colour\nwritten as `green`) stops the build with a plain message instead of failing at the first post.\n\n## Set up the webhook\n\n1. In Discord: **Server Settings > Integrations > Webhooks > New Webhook**. Choose the channel,\n   give it a name and picture, and **Copy Webhook URL**.\n2. Put the address in the site's environment as `DISCORD_WEBHOOK_URL`:\n   - **Cloudflare Workers:** `npx wrangler secret put DISCORD_WEBHOOK_URL`, once for each Worker.\n     For local development, put it in `.dev.vars`. The plugin reads it from `process.env`.\n     Workers fill `process.env` with your secrets when `nodejs_compat` is on and the\n     compatibility date is 2025-04-01 or later, which EmDash needs anyway.\n   - **Node:** an environment variable, or your `.env` file.\n3. Give a staging or test site a webhook for a **separate test channel**, so tests never reach\n   your community.\n4. When the site's first entries are in, an admin switches it on under **Plugins > Discord**.\n   Switching it on later doesn't post anything that's already published.\n\nOnly an address of the form `https://discord.com/api/webhooks/<id>/<token>` counts as set up.\nAnything else (another host, extra parameters) is ignored, so a wrong value can't send posts\nsomewhere else.\n\n**Treat the webhook address as a password:** anyone who has it can post in that channel. Keep it\nout of your repository and out of chats. If it leaks, delete the webhook in Discord, make a new\none and set the new address.\n\n## Options\n\n| Option         | Default                                              | What it does                                                                                                                                                                                          |\n| -------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `collections`  | `{ posts: { path: '/posts/{slug}', name: 'post' } }` | The collections that are announced. `path` is the address of an entry, with `{slug}`; `name` is what one entry is called (\"guide\"). Announce only pages people read, never anything visitors send in. |\n| `titleField`   | `'title'`                                            | The field with the entry's title. An entry without a title isn't posted.                                                                                                                              |\n| `summaryField` | `'excerpt'`                                          | The field with a short summary. `null`: no summary.                                                                                                                                                   |\n| `imageField`   | `'featured_image'`                                   | The image field whose picture is shown. `null`: none.                                                                                                                                                 |\n| `taxonomy`     | none                                                 | A taxonomy whose first term is shown at the bottom of the post, such as `'category'`.                                                                                                                 |\n| `termImages`   | none                                                 | A picture for an entry without one, chosen by its term's slug: `{ recipes: '/og/recipes.jpg' }`.                                                                                                      |\n| `defaultImage` | none                                                 | A picture for an entry with no picture of its own and none from its term.                                                                                                                             |\n| `colour`       | Discord's                                            | The colour of the line down the side, as `#rrggbb`.                                                                                                                                                   |\n| `webhookEnv`   | `'DISCORD_WEBHOOK_URL'`                              | The environment variable with the webhook address.                                                                                                                                                    |\n| `postsPerHour` | `30`                                                 | The most posts the site sends in an hour, 1 to 100.                                                                                                                                                   |\n| `dateLocale`   | `'en-GB'`                                            | The language of dates in the panel.                                                                                                                                                                   |\n| `text`         | English                                              | Replaces any of the panel's and the post's words (below).                                                                                                                                             |\n| `order`        | `3`                                                  | Where the panel sits among the editor's panels; lower comes first.                                                                                                                                    |\n\nPictures (`termImages`, `defaultImage`) are a site path (`/og/default.jpg`, made into a full\naddress on your site) or an `https://` address. An entry's own picture comes from its image\nfield: its `url` or `src`, or, for a file in EmDash's media library, EmDash's media address.\n\n## Other languages\n\nEvery text in the panel and the post can be replaced. Only give the ones you change; the others\nstay English:\n\n```js\ndiscord({\n  collections: { posts: { path: '/blog/{slug}', name: 'artikel' } },\n  dateLocale: 'de-DE',\n  text: {\n    newLabel: 'Neu: {kind}',\n    updateLabel: 'Aktualisiert: {kind}',\n    postNow: 'Auf Discord posten',\n    // and the others\n  },\n});\n```\n\n`{kind}` is the collection's `name`, `{date}` a date, and `{setting}` the name of the webhook\nsetting. The default English texts are exported as `DEFAULT_TEXT`, so you can see every key.\n\n## Privacy and security\n\n- **Network:** only `discord.com` (the plugin's `allowedHosts`).\n- **What is sent:** the published entry's title, summary, first term, page address and picture\n  address. Never drafts, never other fields, never anything about readers or editors.\n- **Mentions:** `allowed_mentions` is empty, so a post can't ping anyone, roles and `@everyone`\n  included.\n- **What is published:** the plugin always reads the live, published entry, never the draft, even\n  from the panel.\n- **Storage** (the plugin's own key-value store): for each entry, whether it was posted or failed,\n  when, how many tries, and whether an editor chose not to post it; and this hour's post count.\n  No text from the entries.\n- **Logs:** statuses only, such as \"Discord answered 429 to a post\".\n- **Capabilities:** `content:read`, `network:request`, and `taxonomies:read` when you set\n  `taxonomy`.\n\n## Good to know\n\n- The plugin's id is `discord`. Its records are kept under that id, so keep it if you ever swap\n  versions.\n- Post to a **thread or forum channel**: not yet; only plain webhook addresses are accepted.\n- Retries are every 15 minutes, up to five times; updates wait 24 hours after the last post.\n  These are fixed on purpose, so a channel stays calm.\n\n## Development\n\nThis package lives in the [emdash-plugins](https://github.com/BorislavHr/emdash-plugins)\nrepository.\n\n```sh\npnpm install\npnpm --filter @borislavhr/emdash-plugin-discord test\npnpm --filter @borislavhr/emdash-plugin-discord build\n```\n\n## License\n\n[MIT](./LICENSE)\n","readmeFilename":"","homepage":"https://github.com/BorislavHr/emdash-plugins/tree/main/packages/discord#readme","keywords":["emdash","emdash-plugin","cms","discord","webhook","announcements","astro"],"repository":{"url":"git+https://github.com/BorislavHr/emdash-plugins.git","type":"git","directory":"packages/discord"},"author":{"url":"https://europe4u.online","name":"Borislav Hristov"},"bugs":"https://github.com/BorislavHr/emdash-plugins/issues","license":"MIT"}