Skip to content

Commit 3778c7a

Browse files
docs: center last projects row in landing (#18424)
Co-authored-by: 翠 / green <[email protected]>
1 parent 9b21f69 commit 3778c7a

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

Diff for: docs/.vitepress/theme/components/landing/3. frameworks-section/FrameworksSection.vue

+38-16
Original file line numberDiff line numberDiff line change
@@ -244,26 +244,48 @@ const numFrameworksPerRow = computed(
244244
() => numBlocksPerRow.value - paddedBlocksPerSide.value * 2,
245245
)
246246
247-
/**
248-
* The indexes of the blocks on each row that support framework cards.
249-
*/
250-
const centerIndexes: ComputedRef<{ start: number; end: number }> = computed(
251-
() => {
252-
const startIndex = paddedBlocksPerSide.value
253-
return {
254-
start: startIndex,
255-
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
256-
}
257-
},
258-
)
259-
260247
/**
261248
* How many rows do we need to display all the frameworks?
262249
*/
263250
const numRows: ComputedRef<number> = computed(() => {
264251
return Math.ceil(frameworks.length / numFrameworksPerRow.value)
265252
})
266253
254+
/**
255+
* The indexes of the blocks on each row that support framework cards.
256+
*
257+
* Note that the index of the returned array is 1-based.
258+
*/
259+
const centerIndexes: ComputedRef<{ start: number; end: number }[]> = computed(
260+
() => {
261+
const firstRowsStartIndex = paddedBlocksPerSide.value
262+
const frameworksPerFirstRows =
263+
numBlocksPerRow.value - 2 * paddedBlocksPerSide.value
264+
const lastRowStartIndex =
265+
paddedBlocksPerSide.value +
266+
Math.floor(
267+
(frameworksPerFirstRows -
268+
(frameworks.length % frameworksPerFirstRows)) /
269+
2,
270+
)
271+
return new Array(numRows.value + 1).fill(0).map((_, i) => {
272+
return i < numRows.value ||
273+
frameworks.length % frameworksPerFirstRows === 0
274+
? {
275+
start: firstRowsStartIndex,
276+
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
277+
}
278+
: {
279+
start: lastRowStartIndex,
280+
end:
281+
lastRowStartIndex +
282+
(frameworks.length % frameworksPerFirstRows) +
283+
1,
284+
}
285+
})
286+
},
287+
)
288+
267289
/**
268290
* Generate CSS transformations for each row, to gracefully slide between horizontal positions.
269291
*/
@@ -289,16 +311,16 @@ const rowStyle: ComputedRef<{ transform: string }> = computed(() => {
289311
<template v-for="columnIndex in numBlocksPerRow + 2">
290312
<template
291313
v-if="
292-
columnIndex - 1 >= centerIndexes.start &&
293-
columnIndex - 1 < centerIndexes.end
314+
columnIndex - 1 >= centerIndexes[rowIndex].start &&
315+
columnIndex - 1 < centerIndexes[rowIndex].end
294316
"
295317
>
296318
<FrameworkCard
297319
:framework="
298320
frameworks[
299321
(rowIndex - 1) * numFrameworksPerRow +
300322
(columnIndex - 1) -
301-
centerIndexes.start
323+
centerIndexes[rowIndex].start
302324
]
303325
"
304326
/>

0 commit comments

Comments
 (0)