Skip to content

Commit 255edfa

Browse files
committed
partners: change boolean check to check for undefined in getOrganizationName()
robots: add sitemap index file HomePageSidebarModule: display home page order 0 is lowest priority HomePageSidebarModule: still display current event until end date CVERecord: handle record queries from Google missing CVE- prefix
1 parent e59b297 commit 255edfa

File tree

2 files changed

+73
-30
lines changed

2 files changed

+73
-30
lines changed

src/components/HomePageSidebarModule.vue

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ const currentDate = new Date(new Date().setHours(0, 0, 0, 0));
179179
const showEventCount = 2;
180180
const showNewsCount = 6;
181181
182+
// This is used for news and events that do not have a specified "home page
183+
// order". The number in the definition below must be larger than the largest
184+
// of the 2 above counts.
185+
186+
const noOrderSpecified = 999;
187+
182188
// This defines what's considered close enough (in days) to today for an event
183189
// start date to prioritize its display.
184190
@@ -205,7 +211,7 @@ function topNews() {
205211
206212
const maxNewsItems = Math.min(showNewsCount, newsList.length);
207213
208-
const orderedNews = newsList.toSorted( orderNews);
214+
const orderedNews = newsList.toSorted(orderNews);
209215
210216
const displayNews = orderedNews.slice(0, maxNewsItems);
211217
@@ -226,25 +232,50 @@ function orderNews(news1, news2) {
226232
// News with lowest number displayed first.
227233
// 2) News article date - most recent first.
228234
// 3) News article identifier number - highest first.
235+
//
236+
// An explicitly set home page order of zero will cause the article
237+
// to sort last (i.e., it won't be displayed).
229238
230-
const displayOrder1 = Object.hasOwn(news1, orderAttr)
231-
? news1.displayOnHomepageOrder : 0;
239+
const result = homePageOrder(news1, news2);
232240
233-
const displayOrder2 = Object.hasOwn(news2, orderAttr)
234-
? news2.displayOnHomepageOrder : 0;
241+
return result || news2.date.localeCompare(news1.date) || news2.id - news1.id;
242+
}
235243
236-
if (displayOrder1 || displayOrder2) {
244+
function homePageOrder(newsOrEvent1, newsOrEvent2) {
237245
238-
if (!displayOrder1)
239-
return 1;
246+
// This is a "helper" function used in both the news and events comparison for
247+
// sorting. This will return that the two news/events are the same for
248+
// comparison unless either or both have the "displayOnHomepageOrder"
249+
// attribute set. Zero sorts at the lowest priority (effectively preventing
250+
// the item from being displayed). Highest "priority" order is value 1 and
251+
// descreasing sequentially.
240252
241-
if (!displayOrder2)
242-
return -1;
253+
const displayOrder1 = Object.hasOwn(newsOrEvent1, orderAttr)
254+
? newsOrEvent1.displayOnHomepageOrder : noOrderSpecified;
255+
256+
const displayOrder2 = Object.hasOwn(newsOrEvent2, orderAttr)
257+
? newsOrEvent2.displayOnHomepageOrder : noOrderSpecified;
258+
259+
if (displayOrder1 !== noOrderSpecified
260+
|| displayOrder2 !== noOrderSpecified) {
261+
262+
// Either one or both items have a specified display order.
263+
264+
if (displayOrder2 === displayOrder1)
265+
return 0;
266+
267+
if (displayOrder2 === noOrderSpecified)
268+
return displayOrder1 > 0 ? -1 : 1
243269
244-
return displayOrder1 - displayOrder2;
270+
if (displayOrder1 === noOrderSpecified)
271+
return displayOrder2 > 0 ? 1 : -1;
245272
}
246273
247-
return news2.date.localeCompare(news1.date) || news2.id - news1.id;
274+
// Either both items do or both don't have a specified display order. For
275+
// no display order, the items are the same "weight" for sorting (and need
276+
// another differentiation (e.g., date)).
277+
278+
return displayOrder1 - displayOrder2;
248279
}
249280
250281
function topEvents() {
@@ -289,22 +320,10 @@ function orderEvents(event1, event2) {
289320
// every Monday), we try to display the ones for the current
290321
// day or the next regular event day.
291322
292-
const displayOrder1 = Object.hasOwn(event1, orderAttr)
293-
? event1.displayOnHomepageOrder : 0;
294-
295-
const displayOrder2 = Object.hasOwn(event2, orderAttr)
296-
? event2.displayOnHomepageOrder : 0;
297-
298-
if (displayOrder1 || displayOrder2) {
299-
300-
if (!displayOrder1)
301-
return 1;
302-
303-
if (!displayOrder2)
304-
return -1;
323+
const result = homePageOrder(event1, event2);
305324
306-
return displayOrder1 - displayOrder2;
307-
}
325+
if (result)
326+
return result;
308327
309328
const recurring1 = event1.date.repeat.recurrence !== undefined;
310329
@@ -351,7 +370,8 @@ function selectRecurringEvent(event1, event2) {
351370
352371
// An event day may be undefined because the "repeat.day" value is not
353372
// a valid day name - a real example is the use of "As Needed". In this
354-
// case, the event will sort after any valid recurring event.
373+
// case, the event will sort after any valid recurring event (because its
374+
// value (20) is way beyond the valid day values).
355375
356376
if (event1Day === undefined)
357377
event1Day = 20;
@@ -413,7 +433,10 @@ function isUpcomingEvent(event) {
413433
414434
const days2Start = Math.round((startDate - currentDate) / mSecPerDay);
415435
416-
return days2Start <= upcomingEventDays && days2Start > 0;
436+
const endDate = parseDateString(event.date.end);
437+
438+
return (days2Start <= upcomingEventDays && days2Start > 0
439+
|| currentDate <= endDate);
417440
}
418441
419442
function toggleNewsIconsMap() {

src/views/CVERecord/CVERecord.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default {
123123
}
124124
},
125125
created() {
126-
const cveId = this.$route.query?.id;
126+
const cveId = this.convertShortId(this.$route.query?.id);
127127
if (cveId) {
128128
this.cveId = this.cveIdToUpperCase(cveId);
129129
this.validateCveId();
@@ -162,6 +162,26 @@ export default {
162162
cveIdToUpperCase(cveId) {
163163
return cveId.toUpperCase();
164164
},
165+
convertShortId(cveId) {
166+
167+
// Probably due to the transition from cve.mitre.org to cve.org,
168+
// some Google search results include an "abbreviated" CVE ID in
169+
// the query (without the "CVE-" prefix). It's easy to recognize
170+
// and add the prefix, and preferable to giving the user an error
171+
// message. The given CVE ID must match the pattern exactly.
172+
173+
const shortIdRegex = /^(?<year>\d{4})\p{Pd}(?<id>\d{4,})$/u
174+
const shortIdMatch = shortIdRegex.exec(cveId);
175+
176+
if (!shortIdMatch)
177+
return cveId;
178+
179+
const year = shortIdMatch.groups.year;
180+
const id = shortIdMatch.groups.id;
181+
const fullCveId = `CVE-${year}-${id}`;
182+
183+
return fullCveId;
184+
},
165185
validateCveId() {
166186
if (!this.usecveRecordStore.isValidCveId(this.cveId)) {
167187
this.disabled = true;

0 commit comments

Comments
 (0)