Add code snippet for ICS-generation.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/node_modules/
|
||||||
6
.vscode/extensions.json
vendored
Normal file
6
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"streetsidesoftware.code-spell-checker"
|
||||||
|
]
|
||||||
|
}
|
||||||
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Just an example of how to share events using links
|
||||||
|
|
||||||
|
## How to run the project
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm ci
|
||||||
|
npm start
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom solution example
|
||||||
|
|
||||||
|
### Generate ICS-text from URL quiery parameters
|
||||||
|
|
||||||
|
http://localhost:8080/generate-event?description=Annual+concert+at+the+Moscow+House+of+Music
|
||||||
|
|
||||||
|
### Generate ICS-file from URL quiery parameters
|
||||||
|
http://localhost:8080/generate-event?description=Annual+concert+at+the+Moscow+House+of+Music&output=file
|
||||||
|
|
||||||
|
|
||||||
|
## Third-party examples
|
||||||
|
* https://jekuer.github.io/add-to-calendar-button/ - A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
|
||||||
|
* https://jennamolby.com/ics-link-generator/ - Outlook Calendar (.ICS) Link Generator
|
||||||
|
|
||||||
30
eventTemplate.js
Normal file
30
eventTemplate.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Event example, using a template.
|
||||||
|
exports.eventTemplate = {
|
||||||
|
start: [2022, 05, 19, 19, 00],
|
||||||
|
duration: { hours: 6, minutes: 30 },
|
||||||
|
title: "Орган от барокко до рока",
|
||||||
|
description:
|
||||||
|
"Орган - «король инструментов», которому подвластны все музыкальные стили. В программе хиты групп Queen, Beatles, Deep Purple гармонично соседствуют м такими органными шедеврами, как Токката и фуга реминор Баха, «Готическая сюита» Л. Боэльмана и соло на тему знаменитого 24-го каприса Н. Паганини.",
|
||||||
|
location: "Космодамианская наб., 52, стр. 8, Москва, Россия",
|
||||||
|
url: "https://www.mmdm.ru/",
|
||||||
|
geo: { lat: 37.622504, lon: 55.753215 },
|
||||||
|
// categories: ["10k races", "Memorial Day Weekend", "Boulder CO"],
|
||||||
|
status: "CONFIRMED",
|
||||||
|
busyStatus: "BUSY",
|
||||||
|
organizer: { name: "Светлановский зал", email: "help@mmdm.ru" },
|
||||||
|
// attendees: [
|
||||||
|
// {
|
||||||
|
// name: "Adam Gibbons",
|
||||||
|
// email: "adam@example.com",
|
||||||
|
// rsvp: true,
|
||||||
|
// partstat: "ACCEPTED",
|
||||||
|
// role: "REQ-PARTICIPANT",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: "Brittany Seaton",
|
||||||
|
// email: "brittany@example2.org",
|
||||||
|
// dir: "https://linkedin.com/in/brittanyseaton",
|
||||||
|
// role: "OPT-PARTICIPANT",
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
};
|
||||||
0
index.html
Normal file
0
index.html
Normal file
56
index.js
Normal file
56
index.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const fs = require("fs");
|
||||||
|
const ics = require("ics");
|
||||||
|
const marked = require("marked");
|
||||||
|
|
||||||
|
// Define defaults of HTTP port/host, can be redefined by environment variables.
|
||||||
|
const HTTP_PORT = process.env.HTTP_PORT || 8080;
|
||||||
|
const HTTP_HOST = process.env.HTTP_HOST || "localhost";
|
||||||
|
const README_FILE = "README.md";
|
||||||
|
|
||||||
|
// Init the Express application instance.
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// Just show `README.md` file as a main page.
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
fs.readFile(README_FILE, { encoding: "utf8" }, (error, file) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const html = marked.marked(file);
|
||||||
|
res.send(html);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Generate ICS-file example tuned with URL query parameters.
|
||||||
|
app.get("/generate-event", function (req, res) {
|
||||||
|
// Load event template from the file.
|
||||||
|
const eventTemplate = require("./eventTemplate");
|
||||||
|
let event = JSON.parse(JSON.stringify(eventTemplate.eventTemplate));
|
||||||
|
event.description = req.query.description;
|
||||||
|
ics.createEvent(event, (error, iCalEventText) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response as a file if required.
|
||||||
|
if (req.query.output === "file") {
|
||||||
|
res.set({
|
||||||
|
"Content-Type": "text/calendar",
|
||||||
|
"Content-Disposition": "inline;filename=calendar.ics",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.set({
|
||||||
|
"Content-Type": "text/plain",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.send(iCalEventText);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Starting a HTTP server.
|
||||||
|
console.log(`Server is running on http://${HTTP_HOST}:${HTTP_PORT}...`);
|
||||||
|
app.listen(HTTP_PORT);
|
||||||
1271
package-lock.json
generated
Normal file
1271
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
package.json
Normal file
22
package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "ical-example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "ssh://gitea@git.dev.hsdesign.ru:1224/public/ical-example.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.18.1",
|
||||||
|
"http": "^0.0.1-security",
|
||||||
|
"ical-generator": "^3.4.2",
|
||||||
|
"ics": "^2.35.0",
|
||||||
|
"marked": "^4.0.15"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user