Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean #81

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
# Site Settings ###################################################################

founder : "Amr Abdel-Motaleb"
remote_theme : "bamr87/zer0-mistakes"
theme : "jekyll-theme-zer0"

### Github Information
## Github Information
github_user : &github_user "bamr87"
repository_name : &github_repository "it-journey"
repository : [*github_user, "/", *github_repository] # GitHub username/repo-name
Expand All @@ -52,7 +54,7 @@ domain_ext : ".dev"
sub_domain : &sub_domain ""
baseurl : "" # the subpath of your site, e.g. /blog - Use this if you want this whole repo to be a domain branch
url_dev : ['https://', *sub_domain, '.', *domain, *domain_ext ] # the base hostname & protocol for your site, e.g. http://example.com
url : 'https://bamr87.github.io' # the base hostname & protocol for your site, e.g. http://example.com
url : 'https://it-journey.dev' # the base hostname & protocol for your site, e.g. http://example.com
public_folder : "/assets"
port : 4002 # Jekyll Serve Dev port
dg_port : 4001 # TODO: Doppelganger site. Use this if you want to switch between parallel deployments
Expand Down Expand Up @@ -83,7 +85,7 @@ locale : "en-US"
home_dir : &home '/Users/bamr87/'
local_git : [ *home, 'github' ]
logo : /assets/images/gravatar-small.png # path of logo image to display in the masthead, e.g. "/assets/images/88x88.png"
logo_link : 'https://www.it-journey.dev'
logo_link : [ *url, *baseurl ] # URL to link the logo to, e.g. "/"

teaser : /assets/images/favicon_gpt_computer_retro.png # path of fallback teaser image, e.g. "/assets/images/500x300.png"
info_banner : /assets/images/info-banner-mountain-wizard.png # path of fallback teaser image, e.g. "/assets/images/500x300.png"
Expand Down Expand Up @@ -188,7 +190,7 @@ plugins:
- jekyll-sitemap
- jekyll-seo-tag
- jekyll-paginate
# - jekyll-algolia
- jekyll-relative-links

## Gisgus Plugin #################################################################

Expand Down Expand Up @@ -265,8 +267,6 @@ paginate_path: "/pages/:num/"

# Defaults https://jekyllrb.com/docs/configuration/front-matter-defaults/

nav-file: '_data/navigation/map.yml'

defaults:
# ALL
-
Expand Down Expand Up @@ -323,7 +323,7 @@ defaults:
sidebar:
nav: quickstart

# _posts
# pages/_posts
-
scope:
path: pages/_posts
Expand Down Expand Up @@ -427,9 +427,6 @@ algolia:
search_only_api_key: '3b9200e21085fbebc263950c157b2682'
index_name: dev_it-journey

atom_feed:
path : # blank (default) uses feed.xml

## Style Settings -------------------------------------------------------------

# theme : "zer0-mistakes-jekyll"
Expand All @@ -439,8 +436,6 @@ theme_skin : "dark" # "air", "aqua", "contrast", "dark", "dirt", "
# style : "default" # "default", "dark", "light", "solarized-dark", "solarized-light"
# remote_style : "bamr87/zer0-mistakes"



theme_color:
main: #007bff
secondary: #6c757d
Expand Down Expand Up @@ -469,7 +464,7 @@ theme_color:
## Copyright Settings --------------------------------------------------------------

cr_year: 2024
cr_entity: "Amr"
cr_entity: *name
cr_lisense: "MIT"

## Sitemap Settings --------------------------------------------------------------
Expand Down
46 changes: 32 additions & 14 deletions script/zer0.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
#!/usr/bin/env python3
def convert_md_to_bash(md_file_path, bash_file_path):
with open(md_file_path, 'r') as md_file, open(bash_file_path, 'w') as bash_file:
bash_file.write('#!/bin/bash\n') # add shebang line
shell_script_mode = False
import os

def convert_md_to_files(md_file_path):
language_files = {}
language_mode = None
language_extensions = {'python': '.py', 'shell': '.sh'}
shebang_lines = {'python': '#!/usr/bin/env python3\n', 'shell': '#!/bin/bash\n'}

output_folder = "script"
os.makedirs(output_folder, exist_ok=True)

with open(md_file_path, 'r') as md_file:
for line in md_file:
if '```shell' in line:
shell_script_mode = True
if line.startswith('```'):
if language_mode:
language_mode = None
else:
language = line.strip('`\n')
if language in language_extensions:
language_mode = language
if language not in language_files:
output_file_path = os.path.join(output_folder, os.path.basename(md_file_path).replace('.md', language_extensions[language]))
language_file = open(output_file_path, 'w')
if language in shebang_lines:
language_file.write(shebang_lines[language])
language_files[language] = language_file
continue
elif '```' in line and shell_script_mode:
shell_script_mode = False
continue
if shell_script_mode:
bash_file.write(line)
else:
bash_file.write(f'# {line}')

convert_md_to_bash('zer0.md', 'zer0.sh')
if language_mode:
language_files[language_mode].write(line)

for language_file in language_files.values():
language_file.close()

convert_md_to_files('zer0.md')
145 changes: 72 additions & 73 deletions script/zer0.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,103 @@ system_profiler SPHardwareDataType | awk '/Model Name:|Model Identifier:|Model N
system_profiler SPSoftwareDataType | awk '/System Version:|Kernel Version:/ {print $0}'

# install and update prerequisites

brew install git
brew install gh
brew install docker
brew install --cask docker
brew install --cask visual-studio-code
# Or use the following to set the environment variables
# Or enter them in the terminal

echo "Please enter your GitHub username:"
read GHUSER
export GHUSER

echo "Please enter your Git repository name:"
read GIT_REPO
export GIT_REPO
export GITHOME=~/github
export GHUSER=bamr87
export GIT_REPO=zer0-mistakes
export ZREPO=$GITHOME/$GIT_REPO
# Confirm the environment variables by echoing them and logging them to a file

# Confirm the environment variables by echoing them

echo $GITHOME # /Users/bamr87/github
echo $GHUSER # bamr87
echo $GIT_REPO # zer0-mistakes
echo $ZREPO # /Users/bamr87/github/zer0-mistakes
echo "$(date) - Log started" > env-variables.log
echo -e "GITHOME: $GITHOME\nGHUSER: $GHUSER\nGIT_REPO: $GIT_REPO\nZREPO: $ZREPO" >> env-variables.log
# Set your Git email and name to tag your commits
# If the GIT_ID is set, use it to tag your commits. "https://github.com/settings/emails"

git config --global user.email "[email protected]"
git config --global user.name "$GHUSER"
# If you didnt already set it in the previous step
# FIXME: quotes in comments dont work

echo "What is your Github ID?"
read GIT_ID

# Set your email using ID

git config --global user.email "[email protected]"
git config --global user.email "[email protected]"
if [ -n "$GIT_ID" ]; then
git config --global user.email "[email protected]"
fi
# confirm your email

git config -l

# Initialize your github repository

gh repo create $GHUSER/$GIT_REPO --public
git config -l | tee -a env-variables.log
# Create your github home directory and repo

mkdir -p $ZREPO
# Initialize your github repository

gh repo create $GIT_REPO --gitignore Jekyll -l mit --public
# If new repo, initialize it

cd $ZREPO
git init
echo "# Building new report from $ZREPO" >> README.md
git remote add origin https://github.com/${GHUSER}/${GIT_REPO}.git
git pull origin main

# Create a README.md file based on the zer0.md file from this repo
curl https://raw.githubusercontent.com/bamr87/it-journey/master/zer0.md > README.md
git add README.md
git commit -m "first commit"
git commit -m "Init $GIT_REPO"
git branch -M main
git remote add origin https://github.com/${GHUSER}/${GIT_REPO}.git
git push -u origin main

# Open your new github repository in the browser

open https://github.com/${GHUSER}/${GIT_REPO}

# Create a new Gemfile
cd $ZREPO
jekyll new ./ --force
bundle install
# If running MacOS
bundle add webrick
bundle install
jekyll serve
cd $ZREPO
bundle update
bundle install
jekyll serve
code _config.yml
cd $ZREPO
wget https://raw.githubusercontent.com/bamr87/it-journey/master/favicon.ico
bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32 java
# find theme path
bundle info --path minima
JEKYLL_THEME=$(bundle info --path minima)
echo $JEKYLL_THEME
cd $JEKYLL_THEME

cp -aR $JEKYLL_THEME/* $ZREPO
bundle remove jekyll-theme-minima
#_config.yml
# Build settings
# theme: minima
plugins:
- jekyll-feed
bundle remove minima --install
jekyll serve
{%- raw -%}
touch Gemfile

# Write the non-commented lines to the Gemfile
echo 'source "https://rubygems.org"' >> Gemfile
echo "gem 'github-pages' , '231'" >> Gemfile
echo "gem 'jekyll' , '3.9.5'" >> Gemfile
echo "gem 'jekyll-theme-zer0'" >> Gemfile
echo "group :jekyll_plugins do" >> Gemfile
echo " gem 'jekyll-feed', \"~> 0.17\"" >> Gemfile
echo " gem 'jekyll-sitemap' , \"~> 1.4.0\"" >> Gemfile
echo " gem 'jekyll-seo-tag', \"~> 2.8.0\"" >> Gemfile
echo " gem 'jekyll-paginate', \"~> 1.1\"" >> Gemfile
echo "end" >> Gemfile
# Download the _config.yml file from the jekyll-theme-zer0 repo

curl https://raw.githubusercontent.com/bamr87/zer0-mistakes/main/_config.yml > _config.yml
# Create a new Dockerfile
cd $ZREPO
mkdir _layout
cd _layout
echo "{{ content }}" >> default.html
{% endraw %}
#tree #alias #zshrc #profile
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
echo alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" >> ~/.zshrc

tree
cd -
d=$(date +%Y-%m-%d)
echo "$d"
cd $ZREPO/_posts
wget -O $d-home.md https://raw.githubusercontent.com/bamr87/it-journey/master/home.md
touch Dockerfile

# Write the content to the Dockerfile
echo "# Use an official Ruby runtime as a parent image" >> Dockerfile
echo "FROM ruby:2.7.4" >> Dockerfile
echo "# escape=\\" >> Dockerfile
echo "ENV GITHUB_GEM_VERSION 231" >> Dockerfile
echo "ENV JSON_GEM_VERSION 1.8.6" >> Dockerfile
echo "ENV GIT_REPO ${GIT_REPO}" >> Dockerfile
echo "WORKDIR /app" >> Dockerfile
echo "ADD . /app" >> Dockerfile
echo "RUN gem update --system 3.3.22" >> Dockerfile
echo "RUN bundle update" >> Dockerfile
echo "RUN bundle install" >> Dockerfile
echo "RUN bundle clean --force" >> Dockerfile
echo "EXPOSE 4000" >> Dockerfile
echo 'CMD ["bundle", "exec", "jekyll", "serve", "--host", "0.0.0.0"]' >> Dockerfile
# build the docker image based on the Dockerfile
docker build -t ${GIT_REPO} .
# Run the container in detached mode
docker run -d -p 4000:4000 -v ${ZREPO}:/app --name zer0_container ${GIT_REPO}

# Start the container and run the CMD line from the Dockerfile
docker start zer0_container

open http://localhost:4000/
46 changes: 32 additions & 14 deletions script/zer0_md_to_sh.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
def convert_md_to_bash(md_file_path, bash_file_path):
with open(md_file_path, 'r') as md_file, open(bash_file_path, 'w') as bash_file:
bash_file.write('#!/bin/bash\n') # add shebang line
shell_script_mode = False
import os

def convert_md_to_files(md_file_path):
language_files = {}
language_mode = None
language_extensions = {'python': '.py', 'shell': '.sh'}
shebang_lines = {'python': '#!/usr/bin/env python3\n', 'shell': '#!/bin/bash\n'}

output_folder = "script"
os.makedirs(output_folder, exist_ok=True)

with open(md_file_path, 'r') as md_file:
for line in md_file:
if '```shell' in line:
shell_script_mode = True
if line.startswith('```'):
if language_mode:
language_mode = None
else:
language = line.strip('`\n')
if language in language_extensions:
language_mode = language
if language not in language_files:
output_file_path = os.path.join(output_folder, os.path.basename(md_file_path).replace('.md', language_extensions[language]))
language_file = open(output_file_path, 'w')
if language in shebang_lines:
language_file.write(shebang_lines[language])
language_files[language] = language_file
continue
elif '```' in line and shell_script_mode:
shell_script_mode = False
continue
if shell_script_mode:
bash_file.write(line)
else:
bash_file.write(f'# {line}')

convert_md_to_bash('zer0.md', 'zer0.sh')
if language_mode:
language_files[language_mode].write(line)

for language_file in language_files.values():
language_file.close()

convert_md_to_files('zer0.md')
Loading
Loading