简体   繁体   中英

Generate ical file with Meteor

Is there some workaround to generate ical files from meteor (javascript)?.

I've have found this https://github.com/sebbo2002/ical-generator but I don't know how to use it into a Meteor project. Thanks.

If you have npm package installed, you can use it with Npm.require :

var ical = Npm.require('ical-generator')

Previously it was done with __meteor_bootstrap__ , but it's outdated.

However, this will only work if you have ical-generator installed properly, and would require installing it manually every time you share project with someone. A better solution is to set a dependency in package.

To do so, create /packages/ical folder and /packages/ical/package.js file with the following content:

Package.describe({
  summary: "Write something meaningful here"
});

Npm.depends({'ical-generator': '0.1.1'});

In the beginning you need to install npm module:

To install an npm module in a Meteor app :

  • cd .meteor/local/build/server
  • npm install ical-generator

Then use it:

var ical = __meteor_bootstrap__.require('ical-generator');

cal = ical();

cal.setDomain('example.com');

cal.addEvent({
    start: new Date(new Date().getTime() + 3600000),
    end: new Date(new Date().getTime() + 7200000),
    summary: 'Example Event',
    description: 'It works ;)',
    organizer: {
        name: 'Organizer\'s Name',
        email: 'organizer@example.com'
    },
    url: 'http://sebbo.net/'
});

console.log(cal.toString());

In case you would like to serve iCal file via http with cal.serve(res) method you have 2 ways to go, both are described here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM