Add :Closed by default feature, Add autoset main heading

This commit is contained in:
octospacc 2022-04-13 12:17:25 +02:00
parent 38e94da543
commit 320df24922
3 changed files with 138 additions and 36 deletions

View File

@ -1,4 +1,4 @@
### Bachecoctt ### Bachecoctt :Closed
A collection of some of my saved links and resources, A collection of some of my saved links and resources,
neatly (I hope) categorized for everyone! neatly (I hope) categorized for everyone!
@ -14,4 +14,4 @@ uwu links..
### Finestra test 2 ### Finestra test 2
- [Link 1](google.com) - [Link 1](google.com)
- [Link 2](example.com) - [Link 2](example.com)

93
Source/Generate.py Normal file → Executable file
View File

@ -35,40 +35,48 @@ BaseHTML = """
<div id="Background"> <!-- https://pixelfed.uno/i/web/post/419157143827461664 (CC BY-SA 4.0) --> <div id="Background"> <!-- https://pixelfed.uno/i/web/post/419157143827461664 (CC BY-SA 4.0) -->
<img src="https://i.imgur.com/GwCgSFC.png"> <!-- https://i.imgur.com/5bdkMlg.gif --> <img src="https://i.imgur.com/GwCgSFC.png"> <!-- https://i.imgur.com/5bdkMlg.gif -->
</div> </div>
<div class="InfoWindow"> {INFO}
<label for="{TITLE}-Toggle"><p>Info Open/Close</p></label>
<input type="checkbox" id="{TITLE}-Toggle">
<div class="InfoWindowBody">
{INFO}
</div>
</div>
{BOARDS} {BOARDS}
</body> </body>
</html> </html>
""" """
BoardHTML = """ InfoHTML = """
<div class="window"> <div class="InfoWindow">
<div class="title-bar"> <label for="{TITLE}-Toggle"><p>Info Open/Close</p></label>
<div class="title-bar-text"> <input type="checkbox" id="{TITLE}-Toggle" {CHECKBOX}>
{TITLE} <div class="InfoWindowBody">
</div> <{H}>{TITLE}</{H}>
<div class="title-bar-controls"> {CONTENT}
<label for="{TITLE}-Toggle"><pre></pre></label>
</div>
</div>
<input type="checkbox" id="{TITLE}-Toggle">
<div class="window-body">
{CONTENT}
</div>
</div> </div>
</div>
""" """
# TODO: Just make it work with any heading by itself.. smh BoardHTML = """
MainHeading = 'h3' <div class="window">
<div class="title-bar">
<div class="title-bar-text">
{TITLE}
</div>
<div class="title-bar-controls">
<label for="{TITLE}-Toggle"><pre></pre></label>
</div>
</div>
<input type="checkbox" id="{TITLE}-Toggle" {CHECKBOX}>
<div class="window-body">
{CONTENT}
</div>
</div>
"""
from markdown import Markdown from markdown import Markdown
MainHeading = ''
def SetMainHeading(Data):
global MainHeading
MainHeading = 'h' + Data.split('<h')[1].split('>')[0]
def SplitPop(String, Key): def SplitPop(String, Key):
List = String.split(Key) List = String.split(Key)
for i,s in enumerate(List): for i,s in enumerate(List):
@ -87,31 +95,43 @@ def GetDataHTML():
def GetBoards(Data): def GetBoards(Data):
Boards = SplitPop(Data, '<{}>'.format(MainHeading)) Boards = SplitPop(Data, '<{}>'.format(MainHeading))
for i,b in enumerate(Boards):
for b in range(len(Boards)): Boards[i] = '<{}>'.format(MainHeading) + b
Boards[b] = '<{}>'.format(MainHeading) + Boards[b]
return Boards return Boards
def GenBoard(Data): def GetBoardParams(Title):
if Title.endswith(':Closed'):
Checkbox = 'checked'
Title = Title[:-len(':Closed')-1]
else:
Checkbox = ''
return (Title, Checkbox)
def GenBoard(Data, Template):
Elements = SplitPop( Elements = SplitPop(
SplitPop( SplitPop(
Data, Data,
'<{}>'.format(MainHeading))[0], '<{}>'.format(MainHeading))[0],
'</{}>'.format(MainHeading)) '</{}>'.format(MainHeading))
Board = BoardHTML.format(
TITLE=Elements[0], Title, Checkbox = GetBoardParams(Elements[0])
Board = Template.format(
H=MainHeading,
TITLE=Title,
CHECKBOX=Checkbox,
CONTENT=Elements[1] CONTENT=Elements[1]
) )
return Board return Board
def WriteHTML(Info, Boards): def WriteHTML(Info, Boards):
Path = 'WebPinBoard.html' Path = 'index.html'
InfoBoard = GenBoard(Info, InfoHTML)
HTMLBoards = '' HTMLBoards = ''
for b in Boards: for b in Boards:
HTMLBoards += GenBoard(b) HTMLBoards += GenBoard(b, BoardHTML)
Title = SplitPop( Title = SplitPop(
SplitPop( SplitPop(
@ -119,13 +139,16 @@ def WriteHTML(Info, Boards):
'<{}>'.format(MainHeading))[0], '<{}>'.format(MainHeading))[0],
'</{}>'.format(MainHeading))[0] '</{}>'.format(MainHeading))[0]
Title, Checkbox = GetBoardParams(Title)
try: try:
with open(Path, 'w') as f: with open(Path, 'w') as f:
f.write( f.write(
BaseHTML.format( BaseHTML.format(
LICENSE=LICENSE, LICENSE=LICENSE,
TITLE=Title, TITLE=Title,
INFO=Info, CHECKBOX=Checkbox,
INFO=InfoBoard,
BOARDS=HTMLBoards)) BOARDS=HTMLBoards))
return True return True
except Exception: except Exception:
@ -134,7 +157,9 @@ def WriteHTML(Info, Boards):
exit(1) exit(1)
def Main(): def Main():
Boards = GetBoards(GetDataHTML()) Data = GetDataHTML()
SetMainHeading(Data)
Boards = GetBoards(Data)
Info = Boards[0] Info = Boards[0]
Boards.pop(0) Boards.pop(0)
WriteHTML(Info, Boards) WriteHTML(Info, Boards)

77
Source/index.html Normal file
View File

@ -0,0 +1,77 @@
<!DOCTYPE html>
<!--
WebPinBoard
Copyright (C) 2022, OctoSpacc
https://gitlab.com/octospacc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bachecoctt</title>
<link rel="stylesheet" href="https://unpkg.com/98.css"> <!-- Credits: https://github.com/jdan/98.css -->
<link rel="stylesheet" href="Style.css">
</head>
<body>
<div id="Background"> <!-- https://pixelfed.uno/i/web/post/419157143827461664 (CC BY-SA 4.0) -->
<img src="https://i.imgur.com/GwCgSFC.png"> <!-- https://i.imgur.com/5bdkMlg.gif -->
</div>
<div class="InfoWindow">
<label for="Bachecoctt-Toggle"><p>Info Open/Close</p></label>
<input type="checkbox" id="Bachecoctt-Toggle" checked>
<div class="InfoWindowBody">
<h3>Bachecoctt</h3>
<p>A collection of some of my saved links and resources,<br />neatly (I hope) categorized for everyone!<br />(and example for my <a href="https://gitlab.com/octospacc/WebPinBoard">WebPinBoard</a> software)</p><ul><li>Data.md file License: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></li></ul><p>uwu links..</p>
</div>
</div>
<div class="window">
<div class="title-bar">
<div class="title-bar-text">
Finestra test
</div>
<div class="title-bar-controls">
<label for="Finestra test-Toggle"><pre></pre></label>
</div>
</div>
<input type="checkbox" id="Finestra test-Toggle" >
<div class="window-body">
<ul><li><a href="example.com">Link 1</a></li><li><a href="example.com">Link 2</a></li></ul>
</div>
</div>
<div class="window">
<div class="title-bar">
<div class="title-bar-text">
Finestra test 2
</div>
<div class="title-bar-controls">
<label for="Finestra test 2-Toggle"><pre></pre></label>
</div>
</div>
<input type="checkbox" id="Finestra test 2-Toggle" >
<div class="window-body">
<ul><li><a href="google.com">Link 1</a></li><li><a href="example.com">Link 2</a></li></ul>
</div>
</div>
</body>
</html>