mirror of
https://git.ari.lt/ari.lt/blog.ari.lt.git
synced 2025-02-04 09:39:25 +01:00
update @ Fri 11 Mar 17:47:54 EET 2022
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
parent
eaac6fd875
commit
17d1491976
5 changed files with 160 additions and 11 deletions
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '16 2 * * 4'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'python' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
30
.github/workflows/spt.yml
vendored
Normal file
30
.github/workflows/spt.yml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
name: Static python type-checking
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.8]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install mypy
|
||||
run: |
|
||||
pip install mypy
|
||||
|
||||
- name: Run mypy
|
||||
run: |
|
||||
mypy scripts/blog
|
|
@ -49,4 +49,4 @@
|
|||
"keywords": "management linux http-redirect new website blog opinion article ari-web ari"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
[build]
|
||||
command = "python3 ./scripts/blog build"
|
||||
command = "python3 ./scripts/blog clean && python3 ./scripts/blog build"
|
||||
|
||||
[[redirects]]
|
||||
from = "/git/*"
|
||||
|
|
66
scripts/blog
66
scripts/blog
|
@ -11,15 +11,16 @@ import sys
|
|||
from atexit import register as fn_register
|
||||
from base64 import b64decode, b64encode
|
||||
from datetime import datetime
|
||||
from glob import iglob
|
||||
from html import escape as html_escape
|
||||
from shutil import rmtree
|
||||
from threading import Thread
|
||||
from timeit import default_timer as code_timer
|
||||
from typing import Dict, List, Tuple
|
||||
from typing import Dict, List, Set, Tuple
|
||||
from warnings import filterwarnings as filter_warnings
|
||||
|
||||
from css_html_js_minify import (html_minify, # type: ignore
|
||||
process_single_css_file)
|
||||
from css_html_js_minify import html_minify # type: ignore
|
||||
from css_html_js_minify import process_single_css_file
|
||||
from markdown import markdown # type: ignore
|
||||
from plumbum.commands.processes import ProcessExecutionError # type: ignore
|
||||
from pyfzf import FzfPrompt # type: ignore
|
||||
|
@ -259,6 +260,12 @@ def build(config: Dict) -> Tuple[int, Dict]:
|
|||
log("Building blogs...", "INFO")
|
||||
|
||||
def thread(blog_name: str, blog_meta: Dict):
|
||||
if blog_meta["version"] != BLOG_VERSION:
|
||||
log(
|
||||
f"{blog_name}: unmatching version between {blog_meta['version']} and {BLOG_VERSION}",
|
||||
"WARNING",
|
||||
)
|
||||
|
||||
blog_dir: str = os.path.join(config["blog-dir"], blog_name)
|
||||
os.makedirs(blog_dir, exist_ok=True)
|
||||
|
||||
|
@ -348,6 +355,9 @@ def build(config: Dict) -> Tuple[int, Dict]:
|
|||
def list_blogs(config: Dict) -> Tuple[int, Dict]:
|
||||
"""List blogs"""
|
||||
|
||||
if not config["blogs"]:
|
||||
return log("No blogs to list"), config
|
||||
|
||||
for blog_id, blog_meta in config["blogs"].items():
|
||||
print(
|
||||
f"""ID: {blog_id}
|
||||
|
@ -364,6 +374,9 @@ Keywords: {blog_meta['keywords'].replace(' ', ', ')}
|
|||
def remove_blog(config: Dict) -> Tuple[int, Dict]:
|
||||
"""Remove a blog page"""
|
||||
|
||||
if not config["blogs"]:
|
||||
return log("No blogs to remove"), config
|
||||
|
||||
blog_id: str = pick_blog(config)
|
||||
|
||||
if not blog_id:
|
||||
|
@ -386,6 +399,9 @@ def edit_title(blog: str, config: Dict) -> int:
|
|||
return log("New title cannot be empty")
|
||||
|
||||
config["blogs"][blog]["title"] = b64encode(new_title.encode()).decode()
|
||||
config["blogs"][sanitise_title(new_title, config["blogs"])] = config["blogs"][blog]
|
||||
|
||||
del config["blogs"][blog]
|
||||
|
||||
return EXIT_OK
|
||||
|
||||
|
@ -431,6 +447,9 @@ EDIT_HOOKS: Dict = {
|
|||
def edit(config: Dict) -> Tuple[int, Dict]:
|
||||
"""Edit a blog"""
|
||||
|
||||
if not config["blogs"]:
|
||||
return log("No blogs to edit"), config
|
||||
|
||||
blog_id: str = pick_blog(config)
|
||||
|
||||
if not blog_id:
|
||||
|
@ -466,6 +485,33 @@ def gen_new_config(config: Dict) -> Tuple[int, Dict]:
|
|||
return EXIT_OK, config
|
||||
|
||||
|
||||
def clean(config: Dict) -> Tuple[int, Dict]:
|
||||
"""Clean up current directory"""
|
||||
|
||||
TRASH: Set[str] = {
|
||||
HISTORY_FILE,
|
||||
config["blog-dir"],
|
||||
"index.html",
|
||||
"content/*.min.*",
|
||||
}
|
||||
|
||||
def remove(file: str) -> None:
|
||||
log(f"Removing {file!r}", "REMOVE")
|
||||
|
||||
try:
|
||||
os.remove(file)
|
||||
except IsADirectoryError:
|
||||
rmtree(file)
|
||||
|
||||
for glob_ex in TRASH:
|
||||
for file in iglob(glob_ex, recursive=True):
|
||||
remove(file)
|
||||
|
||||
open(HISTORY_FILE, "w").close()
|
||||
|
||||
return EXIT_OK, config
|
||||
|
||||
|
||||
SUBCOMMANDS: Dict = {
|
||||
"help": dummy,
|
||||
"new": new_blog,
|
||||
|
@ -474,6 +520,7 @@ SUBCOMMANDS: Dict = {
|
|||
"rm": remove_blog,
|
||||
"edit": edit,
|
||||
"new-config": gen_new_config,
|
||||
"clean": clean,
|
||||
}
|
||||
|
||||
|
||||
|
@ -514,13 +561,14 @@ def main() -> int:
|
|||
with open(DEFAULT_CONFIG_FILE, "r") as lcfg:
|
||||
code, config = SUBCOMMANDS[sys.argv[1]](config=json.load(lcfg))
|
||||
|
||||
log("Sorting blogs by creation time...", "CLEANUP")
|
||||
config["blogs"] = dict(
|
||||
map(
|
||||
lambda k: (k, config["blogs"][k]),
|
||||
sorted(config["blogs"], key=lambda k: config["blogs"][k]["time"]),
|
||||
if config["blogs"]:
|
||||
log("Sorting blogs by creation time...", "CLEANUP")
|
||||
config["blogs"] = dict(
|
||||
map(
|
||||
lambda k: (k, config["blogs"][k]),
|
||||
sorted(config["blogs"], key=lambda k: config["blogs"][k]["time"]),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
with open(DEFAULT_CONFIG_FILE, "w") as dcfg:
|
||||
json.dump(config, dcfg, indent=4)
|
||||
|
|
Loading…
Add table
Reference in a new issue