From 03c42c2cdad73391097f08417ef1843c19e97f03 Mon Sep 17 00:00:00 2001 From: Alexander Chernyaev <265195@niuitmo.ru> Date: Thu, 16 Nov 2023 14:28:27 +0300 Subject: [PATCH 1/5] Add head managment --- package.json | 1 + src/application/i18n/messages/en.json | 9 ++++ src/application/services/useBrowserTitle.ts | 14 ++++++ src/application/services/useNote.ts | 13 +++++ src/index.ts | 2 + src/presentation/pages/Home.vue | 11 ++++ src/presentation/pages/Note.vue | 27 +++++++++- src/presentation/pages/NoteSettings.vue | 10 ++++ src/presentation/pages/Settings.vue | 8 ++- yarn.lock | 56 +++++++++++++++++++++ 10 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/application/services/useBrowserTitle.ts diff --git a/package.json b/package.json index cc1dc096..762fbb67 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "jwt-decode": "^3.1.2", "normalize.css": "^8.0.1", "typescript-cookie": "^1.0.6", + "unhead": "^1.8.3", "vue": "^3.3.4", "vue-i18n": "^9.2.2", "vue-router": "^4.2.4" diff --git a/src/application/i18n/messages/en.json b/src/application/i18n/messages/en.json index e72e0db1..7dcc47d7 100644 --- a/src/application/i18n/messages/en.json +++ b/src/application/i18n/messages/en.json @@ -1,4 +1,13 @@ { + "site": { + "titles": { + "home": "NoteX", + "userSettings": "User Settings", + "noteSettings": "Note Settings", + "newNote": "New Note" + } + }, + "auth": { "login": "Login" }, diff --git a/src/application/services/useBrowserTitle.ts b/src/application/services/useBrowserTitle.ts new file mode 100644 index 00000000..9059d08c --- /dev/null +++ b/src/application/services/useBrowserTitle.ts @@ -0,0 +1,14 @@ +/** + * Limit Title length to 50 char + * + * @param title - string to be reduced + */ +export default function limitTitle(title: string): string { + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + if (title.length <= 50) { + return title; + } else { + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + return title.slice(0, 50); + } +} diff --git a/src/application/services/useNote.ts b/src/application/services/useNote.ts index e251aa08..ab8c07ab 100644 --- a/src/application/services/useNote.ts +++ b/src/application/services/useNote.ts @@ -55,6 +55,11 @@ interface UseNoteComposableState { * Load note by custom hostname */ resolveHostname: () => Promise; + + /** + * Title for bookmarks in the browser + */ + title: Ref; } interface UseNoteComposableOptions { @@ -87,6 +92,13 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt */ const router = useRouter(); + /** + * Title identifier + */ + const title = computed(() => { + return note.value?.content.blocks[0].data.text; + }); + /** * Load note by id * @@ -172,6 +184,7 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt return { note, + title, resolveHostname, save, }; diff --git a/src/index.ts b/src/index.ts index 9533474f..29d0e7a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { createApp } from 'vue'; +import { createHead } from 'unhead'; import App from './App.vue'; import i18n from '@/application/i18n'; import router from '@/application/router/index'; @@ -6,6 +7,7 @@ import '@/presentation/styles/index.pcss'; const app = createApp(App); +app.use(createHead); app.use(router); app.use(i18n); app.mount('#app'); diff --git a/src/presentation/pages/Home.vue b/src/presentation/pages/Home.vue index bc342a37..e3fafb6f 100644 --- a/src/presentation/pages/Home.vue +++ b/src/presentation/pages/Home.vue @@ -6,6 +6,17 @@