Skip to content

Commit

Permalink
INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenrod committed Dec 12, 2021
0 parents commit 7dfba6c
Show file tree
Hide file tree
Showing 61 changed files with 42,824 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch localhost",
"type": "firefox",
"request": "launch",
"reAttach": true,
"url": "http://localhost:3000/index.html",
"pathMappings": [
{
"url": "http://localhost:3000/home/trenrod/dev/blog2/node_modules",
"path": "${workspaceFolder}/node_modules"
},
{
"url": "http://localhost:3000/home/trenrod/dev/blog2/src",
"path": "${workspaceFolder}/src"
},
{
"url": "http://localhost:3000",
"path": "${workspaceFolder}"
}
]
}
]
}
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# TreNrod`s Blog

## System requirements

- Linux system (tested with Ubuntun 20.04 in WSL2)
- Python 3.8
- Docker
- node 12 with npm

## Setup

### Install tools and libs

- Start planuml server as docker container
- ```docker run -d -p 8080:8080 plantuml/plantuml-server:jetty```
- Install required python libs in venv
```sh
# Create virtual environment
python3 -m venv .venv
# Activate virual environment
source ./venv/bin/activate
# Install required python libs
pip install -r requirements.txt
```
- Install libs for frontend
```sh
npm install
```

### Configuration
Following files need to be created and configured

- deployment/inventory.yaml
- This file should contain at least one server and all the information needed to connect to it
```yaml
blogserver:
hosts:
sandbox:
ansible_host: [IP_ADDRESS_OF_THE_SERVER]
ansible_port: [SSH_PORT USUALLY 22]
ansible_user: [SSH USERNAME]
ansible_ssh_private_key_file: [PATH THE PRIVATE KEY OF THE SSH USER]
```
- deployment/inventory.yaml
```yaml
website_url: [WEBSITE_HOSTNAME]
website_email: [YOUR EMAIL]
```

## Development

- Frontend development
```shell
npm run start
```
- Create new blog entry
```shell
python3 blogposttools/main.py create
```
- This returns the newly created blogpost which can be editet and viewed in the browser during development

## Deployment
- Build meta data
```shell
python3 blogposttool/main.py buil
```
- Build frontend and upload
```shell
ansible-playbook deployment/playbooks/build_and_upload_blog.yaml -i deployment/inventory.yam
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions blogposttool/build_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os.path
from os import path
from typing import List, Dict
import json
from parse_data import collect_blogpost_metadata
from models.blog_post_meta_data import BlogPostMetaData

script_path = os.path.dirname(os.path.realpath(__file__))


def build():
"""
Updates all meta files like and generates plantuml svg images to reference in the blog posts
"""
blogpost_meta_data: List[BlogPostMetaData] = collect_blogpost_metadata()
# Create last 10 Posts
blogpost_meta_data.sort()
with open(f"{script_path}/../public/data/home_data.json", "w+") as f:
f.write(json.dumps([data.toJSON() for data in blogpost_meta_data], indent=4))

# Create post groups
tags: Dict[str, List[BlogPostMetaData]] = {}
for blogpost_data in blogpost_meta_data:
tag = blogpost_data.tag.lower()
if not tag in tags:
tags[tag] = []
tags[tag].append(blogpost_data)

# Create groups list
with open(f"{script_path}/../public/data/tags.json", "w+") as f:
f.write(json.dumps([value for value in tags.keys()], indent=4))

# Create blogpost per group
for tag in tags.keys():
with open(f"{script_path}/../public/data/tag_{tag}.json", "w+") as f:
f.write(json.dumps([data.toJSON() for data in tags[tag]], indent=4))

# Create and replace ```plantuml with svg images
40 changes: 40 additions & 0 deletions blogposttool/create_blogpost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os.path
from os import path
import json
from datetime import datetime, timezone
import shortuuid

from models.blog_post_meta_data import BlogPostMetaData

script_path = os.path.dirname(os.path.realpath(__file__))


def create():
"""
Crates new blog post file with meta data
"""
blogname = shortuuid.uuid()
script_path = os.path.dirname(os.path.realpath(__file__))
blogFilePath = f"{script_path}/../public/blogs/{blogname}.md"
# Make sure file not already exists
if path.exists(blogFilePath) == True:
print(f"Blog with same file:{blogFilePath} already exists")
return

with open(blogFilePath, "w+") as f:
f.write("```meta\n")
f.write(
json.dumps(
BlogPostMetaData(
"[INSERT TITLE]",
"[INSERT DESCRIPTION]",
"GENERIC",
datetime.now(timezone.utc),
None,
shortuuid.uuid(),
).toJSON(),
indent=4,
)
)
f.write("\n```\n")
print(f"New blog post created: {blogFilePath}")
36 changes: 36 additions & 0 deletions blogposttool/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import argparse

from build_meta import build
from create_blogpost import create


# create the top-level parser
parser = argparse.ArgumentParser(
prog="Blog Post tool",
usage="""
Create new blog template:
python3 main.py create
Prepare for upload, creates meta data and plantuml svg images:
python3 main.py build
""",
)
subparsers = parser.add_subparsers(help="sub-command help")
# create the parser for the "a" command
parser_create = subparsers.add_parser("create", help="Creates a new blog post template")
parser_create.set_defaults(which="create")

# create the parser for the "b" command
parser_build = subparsers.add_parser(
"build", help="Build blog post. Makes ready to upload."
)
parser_build.set_defaults(which="build")

if __name__ == "__main__":
args = parser.parse_args()
if args.which == "build":
build()
elif args.which == "create":
create()
else:
parser.print_help()
Empty file added blogposttool/models/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions blogposttool/models/blog_post_meta_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from datetime import datetime


class BlogPostMetaData:
def __init__(
self, title, description, tag, created: datetime, updated: datetime, id
):
self.title = title
self.description = description
self.tag = tag
self.created: datetime = created
self.updated: datetime = updated
self.id = id
self.raw_data = None

@staticmethod
def fromJson(jsonData: dict):
return BlogPostMetaData(
jsonData["title"],
jsonData["description"],
jsonData["tag"],
datetime.fromisoformat(jsonData["created"]),
datetime.fromisoformat(jsonData["updated"])
if "updated" in jsonData and jsonData["updated"] != None
else None,
jsonData["id"],
)

def toJSON(self) -> dict:
return {
"title": self.title,
"description": self.description,
"tag": self.tag,
"created": self.created.isoformat(),
"updated": self.updated.isoformat() if self.updated != None else None,
"id": self.id,
}

def __lt__(self, other):
return self.created < other.created
Loading

0 comments on commit 7dfba6c

Please sign in to comment.