Skip to content

Commit

Permalink
Merge pull request #84 from MfN-Berlin/testing-drupal-integration
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
maxlisewski authored Dec 18, 2024
2 parents 3d9a8e0 + 26bce9a commit 62b165e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import './src/styles/global.css'

// Version logging
const VERSION = 'v0.1.2'
const VERSION = 'v0.1.3'

export const onClientEntry = () => {
// Temporär Prefetching deaktivieren
Expand Down
120 changes: 112 additions & 8 deletions src/scripts/urlHelper.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,148 @@
import { getLanguageFromPath } from './languageManager';
import { getTranslatedUrl } from '../data/urlMappings';

// Tracking für rekursive Aufrufe
let isDebugging = false;

const debugUrl = (prefix = '') => {
// Verhindere rekursive Debug-Aufrufe
if (isDebugging) return;
isDebugging = true;

try {
if (typeof window === 'undefined') {
console.group('🔍 URL Debug (SSR)');
console.log('Environment: Server Side Rendering');
console.log('Default Config:', {
pathPrefix: '',
hostname: 'mfn-berlin.github.io'
});
console.groupEnd();
return;
}

// Ein einzelner Debug-Block pro URL-Operation
console.group(`🔍 URL Debug ${prefix}`);

// Alle Debug-Informationen in einem Objekt sammeln
const debugInfo = {
url: {
full: window.location.href,
pathname: window.location.pathname,
search: window.location.search,
hash: window.location.hash,
origin: window.location.origin
},
environment: {
hostname: window.location.hostname,
port: window.location.port || '(default)',
protocol: window.location.protocol,
type: getEnvironmentType()
},
language: {
currentPath: window.location.pathname,
detected: getLanguageFromPath(window.location.pathname),
translations: getAvailableTranslations(window.location.pathname)
},
path: {
segments: window.location.pathname.split('/').filter(Boolean),
depth: window.location.pathname.split('/').filter(Boolean).length,
base: getBasePath(),
prefix: getEnvironmentConfig().pathPrefix
},
navigation: {
referrer: document.referrer,
type: getNavigationType(),
timing: window.performance ? window.performance.getEntriesByType('navigation')[0] : null
}
};

// Übersichtliche Ausgabe
console.table(debugInfo.url);
console.table(debugInfo.environment);
console.table(debugInfo.language);
console.table(debugInfo.path);
console.table(debugInfo.navigation);

console.groupEnd();
} finally {
// Debug-Status zurücksetzen
isDebugging = false;
}
};

// Helper functions
const getEnvironmentType = () => {
const hostname = window.location.hostname;
if (hostname === 'mfn-berlin.github.io') return 'GitHub Pages';
if (hostname === 'localhost') return 'Local Development';
if (hostname.includes('test')) return 'Test Environment';
return 'Production';
};

const getBasePath = () => {
const config = getEnvironmentConfig();
return config.pathPrefix || '';
};

const getNavigationType = () => {
if (window.performance) {
const navigation = window.performance.getEntriesByType('navigation')[0];
return navigation ? navigation.type : 'unknown';
}
return 'unknown';
};

const getAvailableTranslations = (path) => {
const translations = {
de: getTranslatedUrl(path, 'de'),
en: getTranslatedUrl(path, 'en')
};
return translations;
};

export const getEnvironmentConfig = () => {
if (typeof window === 'undefined') {
// console.log('SSR: Using default config');
debugUrl('(SSR)');
return {
pathPrefix: '',
hostname: 'mfn-berlin.github.io'
};
}

const hostname = window.location.hostname;
// console.log('Current hostname:', hostname);
debugUrl('(Config)');

// GitHub Pages
if (hostname === 'mfn-berlin.github.io') {
// console.log('Environment: GitHub Pages');
return {
pathPrefix: '',
hostname
};
}

// Other environments (test, production, local)
// console.log('Environment: Other (local/test/prod)');
return {
pathPrefix: '',
hostname
};
};

export const generateUrl = (to, currentPath) => {
debugUrl('(Generate URL)');

// If it's an external URL, return as is
if (to.startsWith('http')) return to;
if (to.startsWith('http')) {
console.log('External URL detected:', to);
return to;
}

// If the URL already has a language prefix, use it
if (to.startsWith('/de/') || to.startsWith('/en/')) {
console.log('URL with language prefix detected:', to);
return to;
}

// Default to German for paths without language prefix
return `/de${to}`;
const finalUrl = `/de${to}`;
console.log('Generated URL:', finalUrl);
return finalUrl;
};

0 comments on commit 62b165e

Please sign in to comment.