-
Notifications
You must be signed in to change notification settings - Fork 0
ical #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ical #20
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { browsers, features } from './data.js'; | ||
|
|
||
| export function generateICal() { | ||
| const ical = [ | ||
| 'BEGIN:VCALENDAR', | ||
| 'VERSION:2.0', | ||
| 'PRODID:-//Web Features Timeline//Baseline Timeline//EN', | ||
| 'CALSCALE:GREGORIAN', | ||
| 'METHOD:PUBLISH', | ||
| 'X-WR-CALNAME:Web Features Timeline', | ||
| 'X-WR-CALDESC:Timeline of web features and browser support', | ||
| '' | ||
| ]; | ||
|
|
||
| // Process features similar to the main app | ||
| const processedFeatures = []; | ||
|
|
||
| Object.entries(features) | ||
| .forEach(([id, data]) => { | ||
| // Get all ship dates from browsers | ||
| const shipDates = Object.entries(data.status?.support || {}) | ||
| .map(([browser, version]) => { | ||
| if (typeof version !== 'string') { | ||
| return null; | ||
| } | ||
| const cleanVersion = version.replace('≤', ''); | ||
| const browserData = browsers[browser]; | ||
| if (!browserData?.releases) { | ||
| return null; | ||
| } | ||
| const release = browserData.releases.find(r => r.version === cleanVersion); | ||
| if (!release) { | ||
| return null; | ||
| } | ||
| return release.date ? { date: parseLocalDate(release.date), browser, version: cleanVersion } : null; | ||
| }) | ||
| .filter(item => item !== null); | ||
|
|
||
| if (!shipDates.length) return; | ||
|
|
||
| // Sort ship dates chronologically | ||
| shipDates.sort((a, b) => a.date - b.date); | ||
|
|
||
| // The newly available date is when the last browser adds support | ||
| const newlyAvailableDate = shipDates[shipDates.length - 1].date; | ||
|
|
||
| // Calculate widely available date (30 months after newly available) | ||
| const widelyAvailableDate = new Date(newlyAvailableDate); | ||
| widelyAvailableDate.setMonth(widelyAvailableDate.getMonth() + 30); | ||
|
|
||
| // Get current date for comparison | ||
| const now = new Date(); | ||
| now.setHours(0, 0, 0, 0); | ||
|
|
||
| // Always add the newly available entry | ||
| processedFeatures.push({ | ||
| id, | ||
| name: data.name || id, | ||
| description: data.description, | ||
| date: newlyAvailableDate, | ||
| displayType: 'newly-available', | ||
| shipDates | ||
| }); | ||
|
|
||
| // Only add widely available entry if the feature is already available and has full browser support | ||
| if (newlyAvailableDate <= now && data.status?.baseline !== false) { | ||
| processedFeatures.push({ | ||
| id, | ||
| name: data.name || id, | ||
| description: data.description, | ||
| date: widelyAvailableDate, | ||
| displayType: 'widely-available', | ||
| shipDates | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| // Sort features by date in ascending order (earliest first) for chronological order in the calendar | ||
| const sortedFeatures = processedFeatures | ||
| .filter(feature => feature && feature.date && !isNaN(feature.date)) | ||
| .sort((a, b) => a.date - b.date); | ||
|
|
||
| // Generate calendar events | ||
| sortedFeatures.forEach(feature => { | ||
| const eventDate = feature.date; | ||
| const formattedDate = formatDateForICal(eventDate); | ||
|
|
||
| // Create event title | ||
| const eventType = feature.displayType === 'newly-available' ? '🆕 Newly Available' : '✅ Widely Available'; | ||
| const title = `${eventType}: ${feature.name}`; | ||
|
|
||
| // Create event description | ||
| const browserInfo = feature.shipDates | ||
| .map(sd => `${sd.browser} ${sd.version}`) | ||
| .join(', '); | ||
|
|
||
| const description = `${feature.description || ''}\n\nBrowser Support: ${browserInfo}`; | ||
|
|
||
| // Create event | ||
| ical.push( | ||
| 'BEGIN:VEVENT', | ||
| `UID:${feature.id}-${feature.displayType}-${formattedDate}@web-features-timeline`, | ||
| `DTSTART;VALUE=DATE:${formattedDate}`, | ||
| `DTEND;VALUE=DATE:${formatDateForICal(new Date(eventDate.getTime() + 24 * 60 * 60 * 1000))}`, | ||
| `SUMMARY:${escapeICalText(title)}`, | ||
| `DESCRIPTION:${escapeICalText(description)}`, | ||
| 'CLASS:PUBLIC', | ||
| 'STATUS:CONFIRMED', | ||
| 'TRANSP:TRANSPARENT', | ||
| 'END:VEVENT' | ||
| ); | ||
| }); | ||
|
|
||
| ical.push('END:VCALENDAR'); | ||
|
|
||
| return ical.join('\r\n'); | ||
| } | ||
|
|
||
| function parseLocalDate(dateString) { | ||
| const [year, month, day] = dateString.split('-').map(Number); | ||
| return new Date(year, month - 1, day); | ||
| } | ||
|
|
||
| function formatDateForICal(date) { | ||
| const year = date.getFullYear(); | ||
| const month = String(date.getMonth() + 1).padStart(2, '0'); | ||
| const day = String(date.getDate()).padStart(2, '0'); | ||
| return `${year}${month}${day}`; | ||
| } | ||
|
|
||
| function escapeICalText(text) { | ||
| return text | ||
| .replace(/\\/g, '\\\\') | ||
| .replace(/;/g, '\\;') | ||
| .replace(/,/g, '\\,') | ||
| .replace(/\n/g, '\\n') | ||
| .replace(/\r/g, '\\r'); | ||
| } | ||
|
|
||
| export function downloadICal() { | ||
| const icalContent = generateICal(); | ||
| const blob = new Blob([icalContent], { type: 'text/calendar;charset=utf-8' }); | ||
| const url = URL.createObjectURL(blob); | ||
|
|
||
| const link = document.createElement('a'); | ||
| link.href = url; | ||
| link.download = 'web-features-timeline.ics'; | ||
| link.style.display = 'none'; | ||
|
|
||
| document.body.appendChild(link); | ||
| link.click(); | ||
| document.body.removeChild(link); | ||
|
|
||
| URL.revokeObjectURL(url); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.