Monorail website theme ===
npm install @mindful-web/marko-web-theme-monorailMonorail website theme
===
To install and use this feature, you must:
1. Import the content metering middleware and add to your content routes:
``diff
// site/routes/content.js
+const contentMetering = require('@mindful-web/marko-web-theme-monorail/middleware/content-metering');
+const config = require('../config/content-meter');
module.exports (app) => {
- app.get('/?:id(\\d{8})', withContent({
+ app.get('/?:id(\\d{8})', contentMetering(config), withContent({
template: content,
queryFragment,
}));
`
2. Add the contentMeter site config object. See below table for defined options/default values.
`diffsite/config/site.js
+const contentMeter = require('./content-meter');
module.exports = {
// ...
+ contentMeter,
// ...
}
`
`js
// site/config/content-meter.js
module.exports = {
enabled: process.env.ENABLE_CONTENT_METER || false,
viewLimit: 5,
}
`
| Key | Default value | Description |
| - | - | - |
| enabled | false | If the feature should be enabled. |viewLimit
| | 3 | The number of content items a viewer can see in timeframe without logging in. |timeframe
| | 30 24 60 60 1000 (30 days in ms) | The timeframe to consider |excludeLabels
| | [] | Content labels that should be excluded from metering. |excludeContentTypes
| | [] | Content types that should be excluded from metering. |excludePrimarySectionIds
| | [] | Sections whose primary content should be excluded from metering. |excludePrimarySectionAlias
| | [] | Sections whose primary content should be excluded from metering. |displayOverlay
| | _None_ | ??? @B77Mills what is this |promoCode
| | _None_ | If present, the Omeda promo code to use with content metering events. |
3. Add the UI display and event tracking component to your core document component (ideally in above-container):`marko
$ const { contentMeterState } = out.global;
view-limit=contentMeterState.viewLimit
display-overlay=contentMeterState.displayOverlay
display-gate=contentMeterState.displayGate
/>
`
5. Adjust the content body template/layout to truncate the body and/or show inline gating options:
`marko
import cm from "@mindful-web/marko-web-theme-monorail/utils/content-meter-helpers";
$ const { content, blockName } = input;
$ const { contentGatingHandler, contentMeterState, req } = out.global;
$ const showOverlay = cm.shouldOverlay(contentMeterState);
$ const requiresReg = cm.restrictContentByReg(contentMeterState, contentGatingHandler, content);
$ let body = content.body;
$ if (showOverlay) body = getContentPreview({ body: content.body, selector: "p:lt(7)" });
is-logged-in=context.isLoggedIn
$ // ...
/>
$ // ...
``