|
| 1 | +--- |
| 2 | +title: Banners |
| 3 | +noindex: true |
| 4 | +sidebar_order: 80 |
| 5 | +--- |
| 6 | + |
| 7 | +You can add arbitrary banners to the top of a page by adding adding an entry to the `BANNERS` array on |
| 8 | +the `banner/index.tsx` file. The `BANNERS` array is an array of objects with the following properties: |
| 9 | + |
| 10 | +```typescript {filename:banner/index.tsx} |
| 11 | +type BannerType = { |
| 12 | + /** This is an array of strings or RegExps to feed into new RegExp() */ |
| 13 | + appearsOn: (string | RegExp)[]; |
| 14 | + /** The label for the call to action button */ |
| 15 | + linkText: string; |
| 16 | + /** The destination url of the call to action button */ |
| 17 | + linkURL: string; |
| 18 | + /** The main text of the banner */ |
| 19 | + text: string; |
| 20 | + /** Optional ISO Date string that will hide the banner after this date without the need for a rebuild */ |
| 21 | + expiresOn?: string; |
| 22 | +}; |
| 23 | +``` |
| 24 | + |
| 25 | + You can add as many banners as you like. If you need to disable all banners, simply delete them from the array. |
| 26 | + |
| 27 | + Each banner is evaluated in order, and the first one that matches will be shown. |
| 28 | + |
| 29 | +Examples: |
| 30 | + |
| 31 | +```typescript {filename:banner/index.tsx} |
| 32 | +// ... |
| 33 | +// appearsOn = []; // This is disabled |
| 34 | +// appearsOn = ['^/$']; // This is enabled on the home page |
| 35 | +// appearsOn = ['^/welcome/']; // This is enabled on the "/welcome" page |
| 36 | +// ... |
| 37 | + |
| 38 | +const BANNERS = [ |
| 39 | + // This one will take precedence over the last banner in the array |
| 40 | + // (which matches all /platforms pages), because it matches first. |
| 41 | + { |
| 42 | + appearsOn: ['^/platforms/javascript/guides/astro/'], |
| 43 | + text: 'This banner appears on the Astro guide', |
| 44 | + linkURL: 'https://sentry.io/thought-leadership', |
| 45 | + linkText: 'Get webinarly', |
| 46 | + }, |
| 47 | + |
| 48 | + // This one will match the /welcome page and all /for pages |
| 49 | + { |
| 50 | + appearsOn: ['^/$', '^/platforms/'], |
| 51 | + text: 'This banner appears on the home page and all /platforms pages', |
| 52 | + linkURL: 'https://sentry.io/thought-leadership', |
| 53 | + linkText: 'Get webinarly', |
| 54 | + }, |
| 55 | +]; |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | +Optionally, you can add an `expiresOn` property to a banner to hide it after a certain date without requiring a rebuild or manual removeal. |
| 60 | +the ISO Date string should be in the format `YYYY-MM-DDTHH:MM:SSZ` to be parsed correctly and account for timezones. |
| 61 | + |
| 62 | +```typescript {filename:banner/index.tsx} |
| 63 | +const BANNERS = [ |
| 64 | + { |
| 65 | + appearsOn: ['^/$'], |
| 66 | + text: 'This home page banner will disappear after 2024-12-06', |
| 67 | + linkURL: 'https://sentry.io/party', |
| 68 | + linkText: 'RSVP', |
| 69 | + expiresOn: '2024-12-06T00:00:00Z', |
| 70 | + }, |
| 71 | +]; |
| 72 | +``` |
0 commit comments