diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index fc6495f3a..057be25f4 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -7,6 +7,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin') const CssMinimizerPlugin = require('css-minimizer-webpack-plugin') const ProcessLocalesPlugin = require('./ProcessLocalesPlugin') const WatchExternalFilesPlugin = require('webpack-watch-external-files-plugin') +const CopyWebpackPlugin = require('copy-webpack-plugin') const isDevMode = process.env.NODE_ENV === 'development' @@ -131,6 +132,18 @@ const config = { filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.join(__dirname, '../node_modules/swiper/modules/{a11y,navigation,pagination}-element.css').replaceAll('\\', '/'), + to: 'swiper.css', + context: path.join(__dirname, '../node_modules/swiper/modules'), + transformAll: (assets) => { + return Buffer.concat(assets.map(asset => asset.data)) + } + } + ] + }) ], resolve: { alias: { diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index 420d35048..9dd0e20f1 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -140,6 +140,18 @@ const config = { new MiniCssExtractPlugin({ filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', + }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.join(__dirname, '../node_modules/swiper/modules/{a11y,navigation,pagination}-element.css').replaceAll('\\', '/'), + to: 'swiper.css', + context: path.join(__dirname, '../node_modules/swiper/modules'), + transformAll: (assets) => { + return Buffer.concat(assets.map(asset => asset.data)) + } + } + ] }) ], resolve: { diff --git a/src/renderer/components/ft-community-post/ft-community-post.js b/src/renderer/components/ft-community-post/ft-community-post.js index a534b46a2..f3a229c18 100644 --- a/src/renderer/components/ft-community-post/ft-community-post.js +++ b/src/renderer/components/ft-community-post/ft-community-post.js @@ -5,7 +5,9 @@ import FtCommunityPoll from '../ft-community-poll/ft-community-poll.vue' import autolinker from 'autolinker' -import { deepCopy, toLocalePublicationString } from '../../helpers/utils' +import { A11y, Navigation, Pagination } from 'swiper/modules' + +import { createWebURL, deepCopy, toLocalePublicationString } from '../../helpers/utils' import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious' export default defineComponent({ @@ -47,6 +49,34 @@ export default defineComponent({ created: function () { this.parseCommunityData() }, + mounted: function () { + if (this.type === 'multiImage' && this.postContent.content.length > 0) { + const swiperContainer = this.$refs.swiperContainer + + /** @type {import('swiper/element').SwiperContainer} */ + const swiperOptions = { + modules: [A11y, Navigation, Pagination], + + injectStylesUrls: [ + // This file is created with the copy webpack plugin in the web and renderer webpack configs. + // If you add more modules, please remember to add their CSS files to the list in webpack config files. + createWebURL('/swiper.css') + ], + + a11y: true, + navigation: true, + pagination: { + enabled: true, + clickable: true + }, + slidesPerView: 1 + } + + Object.assign(swiperContainer, swiperOptions) + + swiperContainer.initialize() + } + }, methods: { parseCommunityData: function () { if ('backstagePostThreadRenderer' in this.data) { diff --git a/src/renderer/components/ft-community-post/ft-community-post.vue b/src/renderer/components/ft-community-post/ft-community-post.vue index 93f8539a8..34379ce28 100644 --- a/src/renderer/components/ft-community-post/ft-community-post.vue +++ b/src/renderer/components/ft-community-post/ft-community-post.vue @@ -59,11 +59,8 @@