Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions astro/src/components/events/EventsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useStore } from '@nanostores/vue';
import { currentSubsite, subsites, type SubsiteId } from '@/stores/subsiteStore';
import { renderMarkdownInline } from '@/utils/markdown';
import { formatDateRange, getUTCYear } from '@/utils/dateUtils';
import { contentMatchesSubsite, normalizeSubsites } from '@/utils/subsites';
import ExternalIcon from '../common/ExternalIcon.vue';

interface EventData {
Expand Down Expand Up @@ -69,13 +70,6 @@ function getYear(event: EventData): number | null {
return isNaN(date.getTime()) ? null : getUTCYear(date);
}

// Helper to normalize subsites to array
function getSubsites(event: EventData): string[] {
if (!event.subsites) return ['all'];
if (Array.isArray(event.subsites)) return event.subsites;
return [event.subsites];
}

// Filter events based on current subsite
const filteredEvents = computed(() => {
const subsite = $subsite.value;
Expand All @@ -85,14 +79,8 @@ const filteredEvents = computed(() => {
return props.events;
}

// Filter by subsite - include events tagged with this subsite or 'all'
return props.events.filter((event) => {
const eventSubsites = getSubsites(event);
return (
eventSubsites.includes('all') ||
eventSubsites.includes(subsite) ||
eventSubsites.some((s) => s.toLowerCase() === subsite.toLowerCase())
);
return contentMatchesSubsite(normalizeSubsites(event.subsites), subsite);
});
});

Expand Down
15 changes: 2 additions & 13 deletions astro/src/components/news/NewsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useStore } from '@nanostores/vue';
import { currentSubsite, subsites, type SubsiteId } from '@/stores/subsiteStore';
import { renderMarkdownInline } from '@/utils/markdown';
import { formatDate, getUTCYear } from '@/utils/dateUtils';
import { contentMatchesSubsite, normalizeSubsites } from '@/utils/subsites';
import ExternalIcon from '../common/ExternalIcon.vue';

interface NewsArticle {
Expand Down Expand Up @@ -45,26 +46,14 @@ onMounted(() => {
}
});

// Helper to normalize subsites to array
function getSubsites(article: NewsArticle): string[] {
if (!article.subsites) return ['all'];
if (Array.isArray(article.subsites)) return article.subsites;
return [article.subsites];
}

// Filter articles based on current subsite
const filteredBySubsite = computed(() => {
const subsite = $subsite.value;
if (subsite === 'global') {
return props.articles;
}
return props.articles.filter((article) => {
const articleSubsites = getSubsites(article);
return (
articleSubsites.includes('all') ||
articleSubsites.includes(subsite) ||
articleSubsites.some((s) => s.toLowerCase() === subsite.toLowerCase())
);
return contentMatchesSubsite(normalizeSubsites(article.subsites), subsite);
});
});

Expand Down
11 changes: 2 additions & 9 deletions astro/src/pages/bare/eu/events.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ import { getCollection } from 'astro:content';
import BareArticleLayout from '../../../layouts/BareArticleLayout.astro';
import EventsTable from '../../../components/bare/EventsTable.astro';
import Insert from '../../../components/Insert.astro';
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

const now = new Date();
const twelveMonthsAgo = new Date(now);
twelveMonthsAgo.setFullYear(twelveMonthsAgo.getFullYear() - 1);

const allEvents = await getCollection('events', (entry) => {
const subsites = entry.data.subsites || [];
return (
(subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0) &&
!entry.data.draft
);
return contentMatchesSubsite(normalizeSubsites(entry.data.subsites), 'eu') && !entry.data.draft;
});

const upcomingEvents = allEvents
Expand Down
12 changes: 2 additions & 10 deletions astro/src/pages/bare/eu/latest/events.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@
* Embedded in Galaxy EU interface - high visibility feed
*/
import { getCollection } from 'astro:content';
import { contentMatchesSubsite, normalizeSubsites } from '../../../../utils/subsites';

const now = new Date();

const allEvents = await getCollection('events', (entry) => {
const subsites = entry.data.subsites || [];
// Filter for EU subsite
return (
(subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0) &&
!entry.data.draft
);
return contentMatchesSubsite(normalizeSubsites(entry.data.subsites), 'eu') && !entry.data.draft;
});

// Get upcoming events
Expand Down
10 changes: 2 additions & 8 deletions astro/src/pages/bare/eu/latest/news.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
* Embedded in Galaxy EU interface - high visibility feed
*/
import { getCollection } from 'astro:content';
import { contentMatchesSubsite, normalizeSubsites } from '../../../../utils/subsites';

const allNews = await getCollection('news');
const newsArticles = allNews
.filter((article) => {
const subsites = article.data.subsites || [];
const isEU =
subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0;
return isEU && !article.data.draft;
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'eu') && !article.data.draft;
})
.sort((a, b) => {
const dateA = a.data.date ? new Date(a.data.date) : new Date(0);
Expand Down
10 changes: 2 additions & 8 deletions astro/src/pages/bare/eu/news.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import { getCollection } from 'astro:content';
import BareArticleLayout from '../../../layouts/BareArticleLayout.astro';
import NewsTable from '../../../components/bare/NewsTable.astro';
import Insert from '../../../components/Insert.astro';
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

const allNews = await getCollection('news');
const newsArticles = allNews
.filter((article) => {
const subsites = article.data.subsites || [];
const isEU =
subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0;
return isEU && !article.data.draft;
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'eu') && !article.data.draft;
})
.sort((a, b) => {
const dateA = a.data.date ? new Date(a.data.date) : new Date(0);
Expand Down
11 changes: 2 additions & 9 deletions astro/src/pages/bare/fr/events.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
import { getCollection } from 'astro:content';
import BareArticleLayout from '../../../layouts/BareArticleLayout.astro';
import EventsTable from '../../../components/bare/EventsTable.astro';
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

const now = new Date();
const twelveMonthsAgo = new Date(now);
twelveMonthsAgo.setFullYear(twelveMonthsAgo.getFullYear() - 1);

const allEvents = await getCollection('events', (entry) => {
const subsites = entry.data.subsites || [];
return (
(subsites.includes('fr') ||
subsites.includes('all') ||
subsites.includes('all-fr') ||
subsites.includes('global') ||
subsites.length === 0) &&
!entry.data.draft
);
return contentMatchesSubsite(normalizeSubsites(entry.data.subsites), 'fr') && !entry.data.draft;
});

const upcomingEvents = allEvents
Expand Down
12 changes: 2 additions & 10 deletions astro/src/pages/bare/fr/latest/events.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@
* Embedded in Galaxy FR interface - high visibility feed
*/
import { getCollection } from 'astro:content';
import { contentMatchesSubsite, normalizeSubsites } from '../../../../utils/subsites';

const now = new Date();

const allEvents = await getCollection('events', (entry) => {
const subsites = entry.data.subsites || [];
// Filter for FR subsite
return (
(subsites.includes('fr') ||
subsites.includes('all') ||
subsites.includes('all-fr') ||
subsites.includes('global') ||
subsites.length === 0) &&
!entry.data.draft
);
return contentMatchesSubsite(normalizeSubsites(entry.data.subsites), 'fr') && !entry.data.draft;
});

// Get upcoming events
Expand Down
10 changes: 2 additions & 8 deletions astro/src/pages/bare/fr/latest/news.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
* Embedded in Galaxy FR interface - high visibility feed
*/
import { getCollection } from 'astro:content';
import { contentMatchesSubsite, normalizeSubsites } from '../../../../utils/subsites';

const allNews = await getCollection('news');
const newsArticles = allNews
.filter((article) => {
const subsites = article.data.subsites || [];
const isFR =
subsites.includes('fr') ||
subsites.includes('all') ||
subsites.includes('all-fr') ||
subsites.includes('global') ||
subsites.length === 0;
return isFR && !article.data.draft;
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'fr') && !article.data.draft;
})
.sort((a, b) => {
const dateA = a.data.date ? new Date(a.data.date) : new Date(0);
Expand Down
10 changes: 2 additions & 8 deletions astro/src/pages/bare/fr/news.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@
import { getCollection } from 'astro:content';
import BareArticleLayout from '../../../layouts/BareArticleLayout.astro';
import NewsTable from '../../../components/bare/NewsTable.astro';
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

const allNews = await getCollection('news');
const newsArticles = allNews
.filter((article) => {
const subsites = article.data.subsites || [];
const isFR =
subsites.includes('fr') ||
subsites.includes('all') ||
subsites.includes('all-fr') ||
subsites.includes('global') ||
subsites.length === 0;
return isFR && !article.data.draft;
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'fr') && !article.data.draft;
})
.sort((a, b) => {
const dateA = a.data.date ? new Date(a.data.date) : new Date(0);
Expand Down
19 changes: 2 additions & 17 deletions astro/src/pages/eu/events/feed.atom.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import { getCollection } from 'astro:content';

function normalizeSubsites(value: unknown): string[] {
if (!value) return [];
return Array.isArray(value) ? value.map((item) => String(item)) : [String(value)];
}

function isEuSubsite(subsites: string[]): boolean {
return (
subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0
);
}
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

function escapeXML(text: string): string {
return text
Expand Down Expand Up @@ -43,8 +29,7 @@ export async function GET() {
const euEvents = events
.filter((event) => {
if (event.data.draft) return false;
const subsites = normalizeSubsites(event.data.subsites);
return isEuSubsite(subsites);
return contentMatchesSubsite(normalizeSubsites(event.data.subsites), 'eu');
})
.sort((a, b) => {
const dateA = a.data.date instanceof Date ? a.data.date : new Date(a.data.date || 0);
Expand Down
11 changes: 2 additions & 9 deletions astro/src/pages/eu/feed.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { getCollection } from 'astro:content';
import { marked } from 'marked';
import { contentMatchesSubsite, normalizeSubsites } from '../../utils/subsites';

const SITE_URL = 'https://galaxyproject.org';
const FEED_TITLE = 'Galaxy Europe';
Expand Down Expand Up @@ -32,15 +33,7 @@ export async function GET() {
.filter((article) => {
// Must have a date
if (!article.data.date) return false;
// Must be for EU subsite
const subsites = article.data.subsites
? Array.isArray(article.data.subsites)
? article.data.subsites
: [article.data.subsites]
: [];
return (
subsites.includes('eu') || subsites.includes('all') || subsites.includes('global') || subsites.length === 0
);
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'eu');
})
.sort((a, b) => {
const dateA = a.data.date instanceof Date ? a.data.date : new Date(a.data.date || 0);
Expand Down
19 changes: 2 additions & 17 deletions astro/src/pages/eu/news/feed.atom.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { getCollection } from 'astro:content';
import { isPublishedDate } from '../../../utils/dateUtils';

function normalizeSubsites(value: unknown): string[] {
if (!value) return [];
return Array.isArray(value) ? value.map((item) => String(item)) : [String(value)];
}

function isEuSubsite(subsites: string[]): boolean {
return (
subsites.includes('eu') ||
subsites.includes('all') ||
subsites.includes('all-eu') ||
subsites.includes('global') ||
subsites.length === 0
);
}
import { contentMatchesSubsite, normalizeSubsites } from '../../../utils/subsites';

function escapeXML(text: string): string {
return text
Expand All @@ -40,8 +26,7 @@ export async function GET() {
.filter((article) => {
if (article.data.draft) return false;
if (!isPublishedDate(article.data.date, now)) return false;
const subsites = normalizeSubsites(article.data.subsites);
return isEuSubsite(subsites);
return contentMatchesSubsite(normalizeSubsites(article.data.subsites), 'eu');
})
.sort((a, b) => {
const dateA = a.data.date instanceof Date ? a.data.date : new Date(a.data.date || 0);
Expand Down
30 changes: 2 additions & 28 deletions astro/src/pages/events/feed.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { getCollection } from 'astro:content';
import { marked } from 'marked';
import { expandSubsites, normalizeSubsites } from '../../utils/subsites';

const JSONFEED_DAYS_AGO_LIMIT = 30;

Expand All @@ -27,28 +28,6 @@ function generateShortId(str: string): string {
return Math.abs(hash).toString(16).slice(0, 8);
}

// Expand "all" subsite to full list of regional subsites
const ALL_SUBSITES = [
'freiburg',
'pasteur',
'belgium',
'ifb',
'genouest',
'erasmusmc',
'elixir-it',
'au',
'eu',
'us',
'global',
];

function expandSubsites(subsites: string[]): string[] {
if (subsites.includes('all')) {
return ALL_SUBSITES;
}
return subsites;
}

function getDaysAgo(date: Date): number {
const now = new Date();
const diff = now.getTime() - date.getTime();
Expand Down Expand Up @@ -84,12 +63,7 @@ export async function GET() {
}
}

// Normalize subsites to array and expand "all"
let subsites: string[] = [];
if (data.subsites) {
subsites = Array.isArray(data.subsites) ? data.subsites : [data.subsites];
}
subsites = expandSubsites(subsites);
const subsites = expandSubsites(normalizeSubsites(data.subsites));

// Get contact info - can be string or array
let contact = '';
Expand Down
Loading
Loading