Skip to content

Commit

Permalink
Create repo for OOP2024
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanandonov committed Feb 20, 2024
0 parents commit 7ad04f1
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/publish_html.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Simple workflow for deploying static content to GitHub Pages
name: Build and deploy static html pages for the SP exercises

on:
# Runs on pushes targeting the default branch
push:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:


# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# changes:
# runs-on: ubuntu-latest
# outputs:
# dockerfile: ${{ steps.changes.outputs.dockerfile }}
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
# - uses: dorny/paths-filter@v2
# id: changes
# with:
# filters: |
# dockerfile:
# - 'Dockerfile'
#
# create-docker-image:
# runs-on: ubuntu-latest
# environment:
# name: github-pages
# needs: changes
# if: ${{ needs.changes.outputs.dockerfile == 'true' }}
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
#
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build and Push Docker Image
# env:
# DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
# run: |
# echo "Building and pushing Docker image..."
# docker buildx build -t $DOCKER_USERNAME/pandoc-fcse:latest --push .

build-htmls:
runs-on: ubuntu-latest
# needs: create-docker-image
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install pandoc
run: sudo apt-get install -y pandoc

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.11 # Adjust the Python version as needed

- name: Install pypandoc
run: |
python -m pip install --upgrade pip
pip install pypandoc
- name: Install xelatex
run: sudo apt-get update&&sudo apt-get install -y texlive-xetex # Install xelatex

- name: Run create_files.py
run: python create_files.py # Convert MD to HTML and PDFs using pypandoc

- name: Create index files
run: python create_index_pages.py # Create a content HTML named index.html in mk and en subfolders

- name: Archive Output Directory
uses: actions/upload-artifact@v2
with:
name: output-html
path: output/output_html # Adjust the path to your output directory
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build-htmls
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: output-html
path: created_htmls
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Make sure the files from the artifact are present
run: ls -l created_htmls
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'created_htmls'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
46 changes: 46 additions & 0 deletions create_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import shutil

import pypandoc

source_folders = ['mk', 'en']

HTML_OUTPUT_DIR = './output/output_html'

PDF_OUTPUT_DIR = './output/output_pdf'


def create_folder(path):
dir_path = os.path.dirname(path)
if not os.path.exists(dir_path):
os.makedirs(dir_path)


for source_folder in source_folders:
for doc in os.listdir(f"./src/{source_folder}"):
doc_path = os.path.join(f"./src/{source_folder}", doc)
html_path = os.path.join(HTML_OUTPUT_DIR, source_folder, doc.replace("md", "html"))
create_folder(html_path)
output = pypandoc.convert_file(
source_file=doc_path,
to='html',
outputfile=html_path,
extra_args=['-s', '--css=style.css']
)

# for source_folder in source_folders:
# for doc in os.listdir(f"./src/{source_folder}"):
# doc_path = os.path.join(f"./src/{source_folder}", doc)
# pdf_path = os.path.join(PDF_OUTPUT_DIR, source_folder, doc.replace("md", "pdf"))
# create_folder(pdf_path)
# output = pypandoc.convert_file(
# source_file=doc_path,
# to='pdf',
# outputfile=pdf_path,
# extra_args=['--listings', '-s', '--pdf-engine=xelatex', '--extract-media=../img']
# )

# shutil.copy2("src/img", "output/img")
shutil.copytree("src/img", "output/output_html/img")
shutil.copy2("style.css", "output/output_html/mk/style.css")
shutil.copy2("style.css", "output/output_html/en/style.css")
29 changes: 29 additions & 0 deletions create_index_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os


def generate_index(html_files_directory):
is_en = html_files_directory.endswith("en")

html_files = [filename for filename in os.listdir(html_files_directory) if
filename.endswith('.html') and not filename.startswith("index")]
html_files.sort(key=lambda el: int(el.split(".")[0])) # Sort the filenames numerically

index_content = '<html>\n<head>\n<meta charset="utf-8" />\n<title>Index</title>\n<link rel="stylesheet" href="style.css" />\n</head>\n<body>\n'
index_content += '<img src="../img/logo_mk.png">'
index_content += '<h1>Аудиториски вежби по Објектно-ориентирано програмирање</h1>\n' if not is_en \
else '<h1>Auditory exercises in Object-oriented programming</h1>\n'

index_content += f'<h2>Содржина</h2>\n' if not is_en else "<h2>Content</h2>"

for filename in html_files:
index_content += f'<a href="{filename}">{"Аудиториска вежба бр." if not is_en else "Auditory exercise #"} {filename.replace(".html", "")}</a><br>\n'

index_content += '</body>\n</html>'

with open(os.path.join(html_files_directory, 'index.html'), 'w') as index_file:
index_file.write(index_content)


if __name__ == "__main__":
generate_index(html_files_directory="./output/output_html/en")
generate_index(html_files_directory="./output/output_html/mk")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pypandoc==1.11
6 changes: 6 additions & 0 deletions src/en/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<img src="../img/logo_mk.png">

# Object-oriented programming
## Exercise 1


Binary file added src/img/logo_en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/logo_mk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/mk/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img src="../img/logo_mk.png">

# Објектно ориентирано програмирање
## Аудиториска вежба 1

136 changes: 136 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* Reset some default styles */
body, h1, h2, h3, h4, h5, h6, p, ul, ol, li {
margin: 0;
padding: 0;
}

/* Set a background color for the entire page */
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 20px;
max-width: 800px; /* Adjust as needed */
margin: 0 auto;
padding: 20px;
}

/* Style headings */
h1, h2, h3, h4, h5, h6 {
margin-bottom: 10px;
color: #333;
}

h1 {
font-size: 28px;
}

h2 {
font-size: 24px;
}

h3 {
font-size: 20px;
}

h4 {
font-size: 18px;
}

h5 {
font-size: 16px;
}

h6 {
font-size: 14px;
}

/* Style paragraphs */
p {
margin-bottom: 20px;
}

/* Style lists */
ul, ol {
margin-bottom: 20px;
}

li {
margin-left: 20px;
}

/* Style links */
a {
color: #007bff;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* Add some spacing and borders for clarity */
hr {
border: none;
border-top: 1px solid #ccc;
margin-top: 20px;
margin-bottom: 20px;
}

/* Highlight code or preformatted text */
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
padding: 10px;
overflow-x: auto;
}

/* Style blockquotes */
blockquote {
border-left: 2px solid #007bff;
margin: 0 0 20px;
padding: 10px 20px;
}

/* Style images */
img {
max-width: 100%;
height: auto;
}

/* Custom class for important text */
.highlight {
background-color: #ffffcc;
padding: 5px;
border: 1px solid #cccccc;
}

/* Custom class for notes */
.note {
background-color: #f0f0f0;
padding: 10px;
border: 1px solid #cccccc;
}

/* Style tables */
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}

th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}

th {
background-color: #f5f5f5;
}

/* Apply some hover effect to table rows */
tr:hover {
background-color: #f0f0f0;
}

0 comments on commit 7ad04f1

Please sign in to comment.