Feat: add big-button plugin

This commit is contained in:
Bertrand Benjamin 2022-08-29 08:01:10 +02:00
parent 735cd0bd59
commit b6b089542e
6 changed files with 102 additions and 1 deletions

View File

@ -43,6 +43,7 @@ PLUGINS = [
"always_modified", "always_modified",
"tag_cloud", "tag_cloud",
"pdf-img", "pdf-img",
"big-button",
] ]
ALWAYS_MODIFIED = True ALWAYS_MODIFIED = True

View File

View File

@ -0,0 +1 @@
from .big_button import *

View File

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""
big_button tags for reStructuredText
==============================
This plugin allows you to use big_button tags from within reST documents.
.. big_button::
:title: Title
:link: ""
:color: default
Description
"""
from __future__ import unicode_literals
from docutils import nodes
from docutils.parsers.rst import directives, Directive
class BigButton(Directive):
optional_arguments = 0
final_argument_whitespace = True
has_content = True
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {
"title": directives.unicode_code,
"link": directives.path,
}
def settings(self):
self.options['content'] = '\n'.join(self.content)
if not self.options.get('title'):
self.options['title'] = 0
if not self.options.get('link'):
self.options['link'] = 0
def html(self):
html = "<div class='button'>\n"
if self.options["link"]:
html += f"<a href={self.options['link']}>"
else:
html += f"<div class='nolink'>"
if self.options["title"]:
html += f"<h3> {self.options['title']}</h3>"
if self.content:
html += "<div class='content'>"
html += f"{self.options['content']}"
html += "</div>"
if self.options["link"]:
html += "</a>"
else:
html += "</div>"
html += "</div>"
return html
def run(self):
self.settings()
return [nodes.raw('', self.html(), format='html')]
def register():
directives.register_directive("big_button", BigButton)

View File

@ -75,6 +75,39 @@ img {
box-shadow: 0px 0px 10px @light-grey; box-shadow: 0px 0px 10px @light-grey;
} }
.button {
margin: 20px;
border: 3px solid @orange;
width: 250px;
height: 150px;
border-radius: 25px;
display: inline-flex;
vertical-align: top;
padding: 5px 15px;
* {
display: flex;
justify-content: center;
flex-direction: column;
gap: 10px;
}
a {
width:100%;
height:100%;
}
.nolink {
width:100%;
height:100%;
}
h3 {
margin: 0px;
}
}
.button:hover {
background-color: @light-grey;
}
aside { aside {
background-color: @sidebar-bg; background-color: @sidebar-bg;
color: @sidebar-text-color; color: @sidebar-text-color;

File diff suppressed because one or more lines are too long