[opt] swiper

This commit is contained in:
xaoxuu 2022-12-11 19:44:51 +08:00
parent 40f6ee4fda
commit 612df73968
5 changed files with 17 additions and 15 deletions

View File

@ -288,8 +288,8 @@ plugins:
# swiper # swiper
swiper: swiper:
enable: true enable: true
css: https://unpkg.com/swiper@6/swiper-bundle.min.css css: https://unpkg.com/swiper@8/swiper-bundle.min.css
js: https://unpkg.com/swiper@6/swiper-bundle.min.js js: https://unpkg.com/swiper@8/swiper-bundle.min.js
# 赫蹏 (Heti) - 专为中文网页内容设计的排版样式增强 # 赫蹏 (Heti) - 专为中文网页内容设计的排版样式增强

View File

@ -2,7 +2,7 @@
* swiper.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ * swiper.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来 * 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
* *
* {% swiper %} * {% swiper [width:max] [effect:cards] %}
* ![img](src) * ![img](src)
* {% endswiper %} * {% endswiper %}
*/ */
@ -10,7 +10,7 @@
'use strict' 'use strict'
module.exports = ctx => function(args, content) { module.exports = ctx => function(args, content) {
args = ctx.args.map(args, ['width']) args = ctx.args.map(args, ['width', 'effect'])
var el = '' var el = ''
function slide() { function slide() {
let imgs = ctx.render.renderSync({text: content, engine: 'markdown'}) let imgs = ctx.render.renderSync({text: content, engine: 'markdown'})
@ -22,10 +22,8 @@ module.exports = ctx => function(args, content) {
}) })
} }
} }
el += '<div class="tag-plugin swiper-container" id="swiper-api"' el += '<div class="tag-plugin gallery swiper" id="swiper-api"'
if (args.width && args.width.length > 0) { el += ' ' + ctx.args.joinTags(args, ['width', 'effect']).join(' ')
el += ' ' + ctx.args.joinTags(args, 'width').join(' ')
}
el += '>' el += '>'
el += '<div class="swiper-wrapper">' el += '<div class="swiper-wrapper">'
slide() slide()

View File

@ -22,8 +22,7 @@ h1.article-title
.md-text.content .md-text.content
position: relative position: relative
margin-bottom: 2rem margin-bottom: 2rem
// display: flex overflow: hidden
// flex-direction: column
&.indent &.indent
>p:not([class]) >p:not([class])
text-indent: 'calc(%s * 2)' % $fs-p text-indent: 'calc(%s * 2)' % $fs-p

View File

@ -1,10 +1,10 @@
:root :root
--swiper-theme-color: $color-theme !important --swiper-theme-color: $color-theme !important
.swiper-container .swiper
width: 100% width: 100%
border-radius: 4px border-radius: 4px
--gap-p: 2rem --gap-p: 2rem
.swiper-container:not(.swiper-container-initialized) .swiper:not(.swiper-initialized)
display: none display: none
div.swiper-slide div.swiper-slide
text-align: center text-align: center
@ -25,12 +25,15 @@ div.swiper-slide
img img
border-radius: 4px border-radius: 4px
.swiper-container[width='max'] div.swiper-slide .swiper[width='max'] .swiper-slide
width: 100% width: 100%
.swiper-container[width='min'] div.swiper-slide .swiper[width='min'] .swiper-slide
width: 25% width: 25%
.swiper[effect='cards'] .swiper-slide
max-width: 75%
.swiper-button-prev,.swiper-button-next .swiper-button-prev,.swiper-button-next
padding: 1rem 0.5rem padding: 1rem 0.5rem
margin-top: -2rem !important margin-top: -2rem !important

View File

@ -241,10 +241,12 @@ if (stellar.plugins.swiper) {
if (swiper_api != undefined) { if (swiper_api != undefined) {
stellar.loadCSS(stellar.plugins.swiper.css); stellar.loadCSS(stellar.plugins.swiper.css);
stellar.loadScript(stellar.plugins.swiper.js, { defer: true }).then(function () { stellar.loadScript(stellar.plugins.swiper.js, { defer: true }).then(function () {
var swiper = new Swiper('.swiper-container', { const effect = swiper_api.getAttribute('effect') || '';
var swiper = new Swiper('.swiper#swiper-api', {
slidesPerView: 'auto', slidesPerView: 'auto',
spaceBetween: 8, spaceBetween: 8,
centeredSlides: true, centeredSlides: true,
effect: effect,
loop: true, loop: true,
pagination: { pagination: {
el: '.swiper-pagination', el: '.swiper-pagination',