[opt] tag-plugin: grid
This commit is contained in:
parent
07a532b262
commit
2adb5f4214
|
@ -2,10 +2,10 @@
|
||||||
* grid.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
|
* grid.js v1.0 | https://github.com/xaoxuu/hexo-theme-stellar/
|
||||||
* 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来)
|
* 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来)
|
||||||
*
|
*
|
||||||
* {% grid [style:block/card] %}
|
* {% grid [bg:box/card] [w:240px] [c:2] [gap:16px] [br:12px] %}
|
||||||
* <!-- cell left -->
|
* <!-- cell -->
|
||||||
* left body
|
* left body
|
||||||
* <!-- cell right -->
|
* <!-- cell -->
|
||||||
* right body
|
* right body
|
||||||
* {% endgrid %}
|
* {% endgrid %}
|
||||||
*/
|
*/
|
||||||
|
@ -13,37 +13,37 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
module.exports = ctx => function(args, content) {
|
module.exports = ctx => function(args, content) {
|
||||||
args = ctx.args.map(args, ['bg'])
|
args = ctx.args.map(args, ['bg', 'w', 'c', 'gap', 'br'])
|
||||||
|
if (args.w == null && args.c == null) {
|
||||||
|
args.w = '240px'
|
||||||
|
}
|
||||||
var el = ''
|
var el = ''
|
||||||
el += '<div class="tag-plugin grid"'
|
el += '<div class="tag-plugin grid"'
|
||||||
el += ' ' + ctx.args.joinTags(args, ['bg']).join(' ')
|
el += ' ' + ctx.args.joinTags(args, ['bg', 'columns']).join(' ')
|
||||||
el += '>'
|
el += ' style="'
|
||||||
|
if (args.w) {
|
||||||
var arr = content.split(/<!--\s*cell (.*?)\s*-->/g).filter(item => item.trim().length > 0)
|
el += `grid-template-columns: repeat(auto-fill, minmax(${args.w}, 1fr));`
|
||||||
if (arr.length > 0) {
|
} else if (args.c) {
|
||||||
var nodes = []
|
el += `grid-template-columns: repeat(${args.c}, 1fr);`
|
||||||
arr.forEach((item, i) => {
|
}
|
||||||
if (i % 2 == 0) {
|
if (args.gap) {
|
||||||
nodes.push({
|
el += `grid-gap:${args.gap};`
|
||||||
header: item
|
}
|
||||||
})
|
el += '"'
|
||||||
} else if (nodes.length > 0) {
|
el += '>'
|
||||||
var node = nodes[nodes.length-1]
|
// 分组
|
||||||
if (node.body == undefined) {
|
var cells = content.split(/<!--\s*cell(.*?)-->/g).filter(item => item.trim().length > 0)
|
||||||
node.body = item
|
for (let cell of cells) {
|
||||||
} else {
|
el += `<div class="cell" style="`
|
||||||
node.body += '\n' + item
|
if (args.br) {
|
||||||
}
|
el += `border-radius:${args.br};`
|
||||||
}
|
}
|
||||||
})
|
el += `">`
|
||||||
nodes.forEach((node, i) => {
|
el += `
|
||||||
el += '<div class="cell" index="' + (i) + '">'
|
${ctx.render.renderSync({text: (cell || ''), engine: 'markdown'}).split('\n').join('')}
|
||||||
el += ctx.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('')
|
</div>
|
||||||
el += '</div>'
|
`
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
el += '</div>'
|
el += '</div>'
|
||||||
|
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
.tag-plugin.grid
|
.tag-plugin.grid
|
||||||
display: grid
|
display: grid
|
||||||
grid-gap: 16px
|
grid-gap: 16px
|
||||||
grid-template-columns: repeat(auto-fill, "calc((100% - 1 * %s) / 2)" % 16px)
|
&[bg]>.cell>
|
||||||
>.cell
|
|
||||||
p:first-child>strong:only-child
|
|
||||||
font-size: 1rem
|
|
||||||
>.cell>
|
|
||||||
p
|
p
|
||||||
line-height: 1.5
|
line-height: 1.5
|
||||||
:first-child
|
:first-child
|
||||||
|
@ -21,7 +17,7 @@
|
||||||
&[bg]>.cell
|
&[bg]>.cell
|
||||||
padding: 1rem
|
padding: 1rem
|
||||||
border-radius: $border-card
|
border-radius: $border-card
|
||||||
&[bg='block']>.cell
|
&[bg='box']>.cell
|
||||||
background: var(--block)
|
background: var(--block)
|
||||||
&[bg='card']>.cell
|
&[bg='card']>.cell
|
||||||
background: var(--card)
|
background: var(--card)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
justify-content: space-between
|
justify-content: space-between
|
||||||
align-items: center
|
align-items: center
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
width: 320px
|
width: 340px
|
||||||
max-width: 100%
|
max-width: 100%
|
||||||
box-shadow: $boxshadow-card
|
box-shadow: $boxshadow-card
|
||||||
border-radius: $border-bar
|
border-radius: $border-bar
|
||||||
|
|
Loading…
Reference in New Issue