major change fixing bugs when running SSR in the project

This commit is contained in:
F4ilji
2025-04-26 22:59:46 +05:00
parent 1df1a1390f
commit 453fb4cccc
55 changed files with 414 additions and 362 deletions
+44 -21
View File
@@ -1,43 +1,66 @@
import slugify from "slugify";
import process from "@inertiajs/inertia-vue3/.eslintrc.js";
export const helpers = {
data() {
},
methods: {
HAS_ACTIVE_PAGE(section) {
if (!this.$page?.props?.ziggy) return false;
if (section.pages) {
return section.pages.some(page => this.IS_SAME_ROUTE(page.path));
}
if (section.subSections) {
return section.subSections.some(subSection => this.HAS_ACTIVE_PAGE(subSection));
}
return false;
},
IS_SAME_ROUTE(route) {
if (route === this.$page.props.ziggy.location) {
if (!this.$page?.props?.ziggy) return false;
const currentLocation = this.$page.props.ziggy.location;
if (!currentLocation) return false;
if (route === currentLocation) {
return true;
}
const currentLocation = this.$page.props.ziggy.location;
const currentUrl = this.$page.props.ziggy.url + '/' + route;
return currentLocation === currentUrl;
},
TEXT_LIMIT(text, symbols) {
if (text.length > symbols) {
let LimitedText
LimitedText = text.substring(0, symbols)
return LimitedText + "..."
try {
const currentUrl = this.$page.props.ziggy.url + '/' + route;
return currentLocation === currentUrl;
} catch {
return false;
}
return text
},
GENERATE_SLUG: function (text) {
return slugify(text, {
lower: true,
strict: true,
locale: 'ru'
});
TEXT_LIMIT(text, symbols) {
if (!text) return '';
if (typeof text !== 'string') return String(text);
return text.length > symbols
? text.substring(0, symbols) + "..."
: text;
},
GENERATE_SLUG(text) {
if (typeof text !== 'string') return '';
try {
return slugify(text, {
lower: true,
strict: true,
locale: 'ru'
});
} catch {
return text.toLowerCase().replace(/\s+/g, '-');
}
},
GET_BASE_URL() {
if (typeof window === 'undefined') {
return process.env.APP_URL || '/'; // Используем env-переменную на сервере
}
return window.location.origin + '/';
}
},
}
};