@fy-/fws-vue 2.1.24 → 2.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,15 +30,19 @@ const props = withDefaults(
30
30
  hash: '',
31
31
  },
32
32
  )
33
+
33
34
  const route = useRoute()
34
35
  const eventBus = useEventBus()
35
36
  const history = useServerRouter()
36
- const prevNextSeo = ref<any>({})
37
+
38
+ const prevNextSeo = ref<{ prev?: string, next?: string }>({})
39
+
37
40
  function isNewPage(page: number) {
38
41
  return (
39
42
  page >= 1 && page <= props.items.page_max && page !== props.items.page_no
40
43
  )
41
44
  }
45
+
42
46
  const pageWatcher = ref<WatchStopHandle>()
43
47
 
44
48
  function next() {
@@ -53,6 +57,7 @@ function next() {
53
57
  hash: props.hash !== '' ? `#${props.hash}` : undefined,
54
58
  })
55
59
  }
60
+
56
61
  function prev() {
57
62
  const page = props.items.page_no - 1
58
63
  if (!isNewPage(page)) return
@@ -76,61 +81,63 @@ function page(page: number): RouteLocationRaw {
76
81
  }
77
82
 
78
83
  function checkPageNumber(page: number = 1) {
84
+ // Reset prev and next
79
85
  prevNextSeo.value.next = undefined
80
86
  prevNextSeo.value.prev = undefined
81
- const pagePlus = page + 1
82
- const pageMinus = page - 1
87
+
83
88
  if (hasFW()) {
84
89
  const url = getURL()
85
- if (pagePlus <= props.items.page_max && url) {
86
- prevNextSeo.value.next
87
- = `${url.Scheme}://${url.Host}${route.path}?page=${pagePlus}${
88
- props.hash !== '' ? `#${props.hash}` : ''}`
89
- }
90
- if (pageMinus >= 1 && url) {
91
- prevNextSeo.value.prev
92
- = `${url.Scheme}://${url.Host}${route.path}?page=${pageMinus}${
93
- props.hash !== '' ? `#${props.hash}` : ''}`
90
+ if (url) {
91
+ if (page + 1 <= props.items.page_max) {
92
+ prevNextSeo.value.next = `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${props.hash !== '' ? `#${props.hash}` : ''}`
93
+ }
94
+ if (page - 1 >= 1) {
95
+ prevNextSeo.value.prev = `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${props.hash !== '' ? `#${props.hash}` : ''}`
96
+ }
94
97
  }
95
98
  }
96
99
  }
97
100
 
101
+ // Watch for changes in the current page number
98
102
  pageWatcher.value = watch(
99
- () => route.query.page,
100
- (v) => {
101
- eventBus.emit(`${props.id}GoToPage`, v || 1)
103
+ () => props.items.page_no,
104
+ (newPage) => {
105
+ checkPageNumber(newPage)
102
106
  },
107
+ { immediate: true }, // Ensure it's called initially
103
108
  )
109
+
104
110
  onMounted(() => {
105
111
  eventBus.on(`${props.id}GoToPage`, checkPageNumber)
106
112
  })
107
113
  onUnmounted(() => {
108
114
  eventBus.off(`${props.id}GoToPage`, checkPageNumber)
109
- // if (pageWatcher.value) pageWatcher.value();
115
+ if (pageWatcher.value) pageWatcher.value()
110
116
  })
111
117
 
118
+ // Initial check
112
119
  checkPageNumber(props.items.page_no)
120
+
121
+ // Setup SEO head
113
122
  useServerHead({
114
123
  link: computed(() => {
115
- const result: any = []
124
+ const links: any[] = []
125
+
116
126
  if (prevNextSeo.value.next) {
117
- result.push({
127
+ links.push({
118
128
  href: prevNextSeo.value.next,
119
129
  rel: 'next',
120
- key: 'next',
121
- hid: 'paging-next',
130
+ key: 'paging-next',
122
131
  })
123
132
  }
124
133
  if (prevNextSeo.value.prev) {
125
- result.push({
134
+ links.push({
126
135
  href: prevNextSeo.value.prev,
127
136
  rel: 'prev',
128
- key: 'prev',
129
- hid: 'paging-prev',
137
+ key: 'paging-prev',
130
138
  })
131
139
  }
132
-
133
- return result
140
+ return links
134
141
  }),
135
142
  })
136
143
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.1.24",
3
+ "version": "2.1.26",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/fy-to/FWJS#readme",