Bashblog v3.0 - cria um microblog em HTML5

Publicado por Raphael Ciribelly (última atualização em 17/03/2021)

[ Hits: 3.038 ]

Download 7215.bashblog.sh




Cria um microblog em HTML5.

Uso:

$ chmod +x bashblog.sh

Executar script:

$ ./bashblog.sh

FUNÇÕES

Cria arquivos necessários:

$ ./bashblog.sh -n

Cria uma sessão:

$ ./bashblog.sh -s

Deleta uma sessão:

$ ./bashblog.sh -ds

Faz uma postagem:

$ ./bashblog.sh -p

Deleta uma postagem:

$ ./bashblog.sh -dp

Abre browser:

$ ./bashblog.sh -b

Obs.: para fazer uma postagem é necessário primeiramente cadastrar uma sessão.

  



Esconder código-fonte

#!/bin/bash

# bashblog v3.0 
# Author: Raphael Ciribelly
# Size: 31666 bytes
# Date: 2020-12-04
# Check: QErNpLY9vAJh9rysLDRyrAaKp82d0Eu2fniouQxPghS0nOnxyvOlnEETiA0qcSDmCN1ThxmVRQXqFOCv3HdcSOadC5vZbU0TdpKkdDdn5KZgyW6ARrDNFKkuBGWamw0uaAallQSDL7IeJrKi9N5ahvkTOu9Su5hN37z8Z08tCI63M66lX14dOau22ayFlOrXzPom7UpnoSiTDuMzi9AiSF5J68SUOUb54D9XqSf2xVE99ybTfUKQxjk5tYbYrXmuZwVLtEcCr9bLsQxMkiHEUxkcSuaDkQvvytbJ74vFJt6MbQttNzWErZw9fhiCYuJQ5BdFJrsDd1nuu8g8RFyEY4FcSknnsAM0nyJ87SDhQNSZ4FW6SMfeRArlyh3iQFeIk6636jvx5VNfRShXhRRyjQZKBcdrkd6qFwRInAldv4xBXmea1GFtPV1aQ2qz2WCOByOBSYDqiXG

# OS: Debian GNU/Linux 10 (buster)
# bash version: GNU bash, versão 5.0.3(1)-release (x86_64-pc-linux-gnu)
# sed version: sed (GNU sed) 4.7
# grep version: grep (GNU grep) 3.3
# vim version: VIM - Vi IMproved 8.1 
# touch version: touch (GNU coreutils) 8.30
# mkdir version: mkdir (GNU coreutils) 8.30
# rm version: rm (GNU coreutils) 8.30
# xargs version: xargs (GNU findutils) 4.6.0.225-235f
# rmdir version: rmdir (GNU coreutils) 8.30

# Variables - set the names inside the double quotes, CONFIGURE!
WEBSITE_NAME="Name Website"
WEBSITE_LINK="https://www.Website.com"
MENU_NAME_1="Home"
MENU_NAME_2="About"
MENU_NAME_3="Blog"
MENU_NAME_4="Downloads"
MENU_NAME_5="Email"
MENU_LINK_1="index.html"
MENU_LINK_2="about.html"
MENU_LINK_3="blog.html"
MENU_LINK_4='downloads.html'
MENU_LINK_5="mailto:contact@email.com"
FEED_LINK="feed.rss"
SOCIAL_NAME_1="Facebook"
SOCIAL_NAME_2="Instagram"
SOCIAL_NAME_3="YouTube"
SOCIAL_LINK_1="link facebook"
SOCIAL_LINK_2="link instagram"
SOCIAL_LINK_3="link youtube"
COPYRIGHT="© 2020 - All rights reserved"
AUTHOR="AUTHOR Website"
LANGUAGE="en-US"
DESCRIPTION="description website"

# Variables - path of files and directories
DIR_WEBSITE="${HOME}/Website"
DIR_POST="${HOME}/Website/post"
DIR_CSS="${HOME}/Website/css"
DIR_IMG="${HOME}/Website/img"
DIR_FILES="${HOME}/Website/files"
DIR_TAGS="${HOME}/Website/tags"
INDEXHTML="${HOME}/Website/${MENU_LINK_1}"
ABOUTHTML="${HOME}/Website/${MENU_LINK_2}"
BLOGHTML="${HOME}/Website/${MENU_LINK_3}"
DOWNLOADSHTML="${HOME}/Website/${MENU_LINK_4}"
FEEDRSS="${HOME}/Website/feed.rss"
STYLE_CSS="${HOME}/Website/css/style.css"
NORMALIZE_CSS="${HOME}/Website/css/normalize.css"
EDITOR="vim"

# checks if files exist
CHECK_FILES(){
for i in ${DIR_WEBSITE} ${DIR_POST} ${DIR_CSS} ${DIR_IMG} ${DIR_FILES} ${DIR_TAGS} ${INDEXHTML} ${ABOUTHTML} ${BLOGHTML} ${DOWNLOADSHTML} ${STYLE_CSS} ${NORMALIZE_CSS};do
[[ ! -e "${i}" ]] && { echo "$i Does not exist." ; exit 1 ; }
done
}

# generates html files
BASE_HTML(){
# index.html
if [[ ! -e "${INDEXHTML}" ]] ; then
cat <<EOF > "${INDEXHTML}"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Home | ${WEBSITE_NAME}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${DESCRIPTION}">
      <meta name="keywords" content="index, ${WEBSITE_NAME}"/>
      <link rel="canonical" href="${WEBSITE_LINK}/${MENU_LINK_1}" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="css/normalize.css">
      <link rel="stylesheet" type="text/css" href="css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a class="active" href="${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a href="${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a href="${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>Index</h2>
         <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
      </main>
      <footer>
         <p>$COPYRIGHT</p>
         <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="${FEED_LINK}">Subscribe</a> </p>
      </footer>
   </body>
</html>

EOF

# about.html
cat <<EOF > "${ABOUTHTML}"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>About | ${WEBSITE_NAME}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${DESCRIPTION}">
      <meta name="keywords" content="about, ${WEBSITE_NAME}"/>
      <link rel="canonical" href="${WEBSITE_LINK}/${MENU_LINK_2}" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="css/normalize.css">
      <link rel="stylesheet" type="text/css" href="css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a href="${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a class="active" href="${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a href="${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a href="${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>About</h2>
         <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
      </main>
      <footer>
         <p>$COPYRIGHT</p>
         <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="${FEED_LINK}">Subscribe</a> </p>
      </footer>
   </body>
</html>

EOF

# blog.html
cat <<EOF > "${BLOGHTML}"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Blog | ${WEBSITE_NAME}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${DESCRIPTION}">
      <meta name="keywords" content="blog, ${WEBSITE_NAME}"/>
      <link rel="canonical" href="${WEBSITE_LINK}/${MENU_LINK_3}" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="css/normalize.css">
      <link rel="stylesheet" type="text/css" href="css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a href="${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a class="active" href="${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a href="${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>Blog</h2>
         <ul class="posts">
         </ul>
      </main>
      <footer>
         <p>$COPYRIGHT</p>
         <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="${FEED_LINK}">Subscribe</a> </p>
      </footer>
   </body>
</html>

EOF

# downloads.html
cat <<EOF > "${DOWNLOADSHTML}"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Downloads | ${WEBSITE_NAME}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${DESCRIPTION}">
      <meta name="keywords" content="downloads, ${WEBSITE_NAME}"/>
      <link rel="canonical" href="${WEBSITE_LINK}/${MENU_LINK_4}" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="css/normalize.css">
      <link rel="stylesheet" type="text/css" href="css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav>
               <ul class="menu_ul">
                  <li><a href="${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a href="${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a class="active" href="${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>Downloads</h2>
      </main>
      <footer>
         <p>$COPYRIGHT</p>
         <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="${FEED_LINK}">Subscribe</a> </p>
      </footer>
   </body>
</html>

EOF

echo "html files successfully created!"

exit 0
else
sleep 0
fi

# POST - check if blog.html file exists to create the post
if [[ -e "${BLOGHTML}" ]] ; then
cat <<EOF > "${post_dir}/${final_date}/${post_title_lower// /-}.html"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Blog | ${post_title}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${description_post}">
      <meta name="keywords" content="${keywords}, ${WEBSITE_NAME}"/>
      <link rel="canonical" href="${WEBSITE_LINK}/post/${post_session_upper// /-}/${final_date}/${post_title_lower// /-}.html" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../../../../../css/normalize.css">
      <link rel="stylesheet" type="text/css" href="../../../../../css/style.css">
   </head>
   <body>
      <main>
         <article class="article-post">
            <header class="header-post">
               <h1>${post_title}</h1>
               <span>by ${AUTHOR} | <time datetime="${final_date_hour}">${final_date_hour2}</time></span>
            </header>
            <p>TEXT HERE</p>
            <footer class="footer-post">
               <p>TAGS: <a href="${DIR_TAGS}/tag_${tag1_lower}.html" rel="tag">${tag1}</a> <a href="${DIR_TAGS}/tag_${tag2_lower}.html" rel="tag">${tag2}</a> <a href="${DIR_TAGS}/tag_${tag3_lower}.html" rel="tag">${tag3}</a> </p>
            </footer>
         </article>
      </main>
      <footer>
         <p>$COPYRIGHT</p>
         <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="../../../../../${FEED_LINK}">Subscribe</a> </p>
      </footer>
   </body>
</html>

EOF

# TAG 1
if [[ ! -e ${DIR_TAGS}/tag_${tag1_lower}.html ]] ; then
cat <<EOF > "${DIR_TAGS}/tag_${tag1_lower}.html"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Blog | ${tag1_upper}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${description_post}">
      <meta name="keywords" content="${keywords}, ${WEBSITE_NAME}"/>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../css/normalize.css">
      <link rel="stylesheet" type="text/css" href="../css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a href="../${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="../${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a class="active" href="../${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a  href="../${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="../${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>TAG: ${tag1_upper}</h2>
         <ul>
<!-- TAG -->         
         </ul>
      </main>
         <footer>
            <p>$COPYRIGHT</p>
            <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="../${FEED_LINK}">Subscribe</a> </p>
         </footer>
   </body>
</html>

EOF

else
sleep 0
fi

# TAG 2
if [[ ! -e ${DIR_TAGS}/tag_${tag2_lower}.html ]] ; then
cat <<EOF > "${DIR_TAGS}/tag_${tag2_lower}.html"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Blog | ${tag2_upper}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${description_post}">
      <meta name="keywords" content="${keywords}, ${WEBSITE_NAME}"/>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../css/normalize.css">
      <link rel="stylesheet" type="text/css" href="../css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a href="../${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="../${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a class="active" href="../${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a href="../${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="../${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>TAG: ${tag2_upper}</h2>
         <ul>
<!-- TAG -->         
         </ul>
      </main>
         <footer>
            <p>$COPYRIGHT</p>
            <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="../${FEED_LINK}">Subscribe</a> </p>
         </footer>
   </body>
</html>
EOF

else
sleep 0
fi

# TAG 3
if [[ ! -e ${DIR_TAGS}/tag_${tag3_lower}.html ]] ; then
cat <<EOF > "${DIR_TAGS}/tag_${tag3_lower}.html"
<!DOCTYPE html>
<html lang="${LANGUAGE}">
   <head>
      <meta charset="UTF-8">
      <title>Blog | ${tag3_upper}</title>
      <meta name="author" content="${AUTHOR}">
      <meta name="robots" content="index, follow" />
      <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
      <meta name="description" content="${description_post}">
      <meta name="keywords" content="${keywords}, ${WEBSITE_NAME}"/>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="../css/normalize.css">
      <link rel="stylesheet" type="text/css" href="../css/style.css">
   </head>
   <body>
      <header>
         <h1>${WEBSITE_NAME}</h1>
            <nav class="menu">
               <ul class="menu_ul">
                  <li><a href="../${MENU_LINK_1}">${MENU_NAME_1}</a></li>
                  <li><a href="../${MENU_LINK_2}">${MENU_NAME_2}</a></li>
                  <li><a class="active" href="../${MENU_LINK_3}">${MENU_NAME_3}</a></li>
                  <li><a href="../${MENU_LINK_4}">${MENU_NAME_4}</a></li>
                  <li><a href="../${MENU_LINK_5}">${MENU_NAME_5}</a></li>
               </ul>
            </nav>
      </header>
      <main>
         <h2>TAG: ${tag3_upper}</h2>
         <ul>
<!-- TAG -->         
         </ul>
      </main>
         <footer>
            <p>$COPYRIGHT</p>
            <p><a href="${SOCIAL_LINK_1}">${SOCIAL_NAME_1}</a> | <a href="${SOCIAL_LINK_2}">${SOCIAL_NAME_2}</a> | <a href="${SOCIAL_LINK_3}">${SOCIAL_NAME_3}</a> | <a href="../${FEED_LINK}">Subscribe</a> </p>
         </footer>
   </body>
</html>
EOF
else
sleep 0
fi

# feed.rss
cat <<EOF > "${FEEDRSS}"
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>${WEBSITE_NAME}</title>
<link>${WEBSITE_LINK}</link>
<description>${DESCRIPTION}</description>
<item>
<title>${post_title}</title>
<link><${WEBSITE_LINK}/${final_date}/${post_title_lower// /-}.html"/link>
<description>${description_post}</description>
</item>
</channel>
</rss> 
EOF

else
echo "ERROR: blog.html Does not exist."
fi
}

# Create directories and execute fuction BASE_HTML
NEW(){
if [[ -d "${DIR_WEBSITE}" ]]; then
echo "Files already exist!"
exit 0
else
echo "Creating the necessary files and folders"
mkdir -v "${DIR_WEBSITE}"      ; \
mkdir -v "${DIR_POST}"      ; \
mkdir -v "${DIR_CSS}"       ; \
mkdir -v "${DIR_IMG}"       ; \
mkdir -v "${DIR_FILES}"     ; \
mkdir -v "${DIR_TAGS}"      ; \
touch "${STYLE_CSS}"        ; \
touch "${NORMALIZE_CSS}"    ; \
BASE_HTML                 ; \
exit 0
fi
}

ADD_SESSION(){

CHECK_FILES

read -ep "Session name: " new_session

# check if variable is null
if [[ -z "${new_session}" ]] ; then
echo "ERROR: name not specified"
exit 1
else
sleep 0
fi

# check if variable has special characters
if [[ "${new_session}" =~ ^[0-9A-Za-z\ ]+$ ]] && [[ "${new_session}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

# variables
local new_session_upper="${new_session^^}"
local new_session_lower="${new_session,,}"
local pattern_ul='<ul class="posts">'

# check if directory already exists 
if [[ ! -d "${DIR_POST}/${new_session_upper// /-}" ]]; then
mkdir -v "${DIR_POST}/${new_session_upper// /-}"
else
echo "ERROR: directory already exists"
exit 1
fi

# add to html tags for list creation below the <ul class="posts"> tag
sed -i '/'"${pattern_ul}"'/a <\!-- SESSION:'"${new_session_upper// /-}"' -->' ${BLOGHTML}
sed -i '/<\!-- SESSION:'"${new_session_upper// /-}"' -->/a <\!-- SESSION-END:'"${new_session_upper// /-}"' -->' ${BLOGHTML}
sed -i 's/<\!-- SESSION:'"${new_session_upper// /-}"' -->/<\!-- SESSION:'"${new_session_upper// /-}"' -->\n<li class="'"${new_session_lower// /-}"'">\n<h3>'"${new_session_upper}"'<\/h3>\n<ul class="'"${new_session_lower// /-}"'">\n<\/ul>/' ${BLOGHTML}
}

DEL_SESSION(){

CHECK_FILES

read -ep "Session name: " session_name

# variables
local session_name_upper="${session_name^^}"
local session_name_lower="${session_name,,}"

# check if session exists
if grep -qow '<ul class="'"${session_name_lower// /-}"'">' ${BLOGHTML} ; then
sleep 0
else
echo "ERROR: Session does not exist!."
exit 1
fi

# asks if you want to delete session
read -p "Delete ${session_name_upper} session??? [y/n]: " question

if [ "${question}" != "${question#[Yy]}" ] ;then
echo "Deleting ${session_name_upper}"
sed -i '/<\!-- SESSION:'"${session_name_upper// /-}"' -->/,/<\!-- SESSION-END:'"${session_name_upper// /-}"' -->/d' ${BLOGHTML}
sed -i '/^<!-- SESSION:'"${session_name_upper// /-}"' .*/,/^<!-- SESSION:'"${session_name_upper// /-}"' .*/d' ${DIR_TAGS}/*.html
grep -rIL "<\!-- SESSION:.*" ${DIR_TAGS}/*.html 2>/dev/null | xargs rm -rv 2>/dev/null
else
echo "preserved "${session_name}".html session"
exit 0
fi

# asks if you want to delete session directory
read -p "Delete directory session ${session_name_upper// /-}??? [y/n]: " question2
read -ep "CAUTION: this will delete all html posts contained in the directory, are you sure you want to continue? [y/n]: " question2

if [[ "${question2}" != "${question2#[Yy]}" ]] ; then
echo "Deleting directory ${session_name_upper// /-}"
rm -rv ${DIR_POST}/${session_name_upper// /-}
else
echo "Directory "${session_name_upper// /-}" preserved"
exit 0
fi
}

ADD_POST(){

CHECK_FILES

read -ep "Add to session: " post_session

# variables
local post_session_upper="${post_session^^}"
local post_session_lower="${post_session,,}"

# check if session exists
if grep -qow '<ul class="'"${post_session_lower// /-}"'">' ${BLOGHTML} ; then
sleep 0
else
echo "ERROR: Session does not exist!."
exit 1
fi

# post dir
local post_dir="${DIR_POST}/${post_session_upper// /-}"

# Date default ISO-8601

# Year
local year=$(date +%Y)

if [[ ! -d "${post_dir}/${year}" ]]; then
mkdir -v "${post_dir}/${year}"
else
sleep 0
fi

# Month
local month=$(date +%m)

if [[ ! -d "${post_dir}/${year}/${month}" ]]; then
mkdir -v "${post_dir}/${year}/${month}"
else
sleep 0
fi

# Day
local day=$(date +%d)

if [[ ! -d "${post_dir}/${year}/${month}/${day}" ]]; then
mkdir -v "${post_dir}/${year}/${month}/${day}"
else
sleep 0
fi

# Final date post.
local final_date="$(date +%Y/%m/%d)"
local final_date_hour="$(date +"%Y-%m-%d %R:%S" | xargs)"
local final_date_hour2="$(date +"%Y-%m-%d - %R:%S" | xargs)"

read -ep "Post title: " post_title

local post_title_upper="${post_title^^}"
local post_title_lower="${post_title,,}"

# check if variable is null
if [[ -z "${post_title}" ]] ; then
echo "ERROR: no name specified"
exit 1
else
sleep 0
fi

# check if variable has special characters
if [[ "${post_title}" =~ ^[0-9A-Za-z\ ]+$ ]] && [[ "${post_title}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

read -p "Keywords: " keywords

# tags - get tag name
for i in 1 2 3
do
read -ep "Tag[${i}]: " tag
eval "tag${i}=${tag// /-}"
done

# variable local - link of the tags to lowercase
local tag1_lower="${tag1,,}"
local tag2_lower="${tag2,,}"
local tag3_lower="${tag3,,}"
local tag1_upper="${tag1^^}"
local tag2_upper="${tag2^^}"
local tag3_upper="${tag3^^}"


# check if variable is null
if [[ -z "${tag1}" ]] ; then
echo "ERROR: no name specified"
exit 1
else
sleep 0
fi

# check if variable is null
if [[ -z "${tag2}" ]] ; then
echo "ERROR: no name specified"
exit 1
else
sleep 0
fi

# check if variable is null
if [[ -z "${tag3}" ]] ; then
echo "ERROR: no name specified"
exit 1
else
sleep 0
fi

# check if variable has special characters
if [[ "${tag1}" =~ ^[0-9A-Za-z\ -]+$ ]] && [[ "${tag1}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

# check if variable has special characters
if [[ "${tag2}" =~ ^[0-9A-Za-z\ -]+$ ]] && [[ "${tag2}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

# check if variable has special characters
if [[ "${tag3}" =~ ^[0-9A-Za-z\ -]+$ ]] && [[ "${tag3}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

# check if variables have the same names
if [[ "${tag1}" == "${tag2}" ]] ; then
echo "ERROR: repeated tag name"
exit 1
elif [[ "${tag1}" == "${tag3}" ]] ; then
echo "ERROR: repeated tag name"
exit 1
elif [[ "${tag2}" == "${tag1}" ]] ; then
echo "ERROR: repeated tag name"
exit 1
elif [[ "${tag2}" == "${tag3}" ]] ; then
echo "ERROR: repeated tag name"
exit 1
elif [[ "${tag3}" == "${tag1}" ]] ; then
exit 1
echo "ERROR: repeated tag name"
exit 1
elif [[ "${tag3}" == "${tag2}" ]] ; then
echo "ERROR: repeated tag name"
exit 1
else
sleep 0
fi

read -p "Description post (150 chars): " description_post

# checks if post already exists
if [[ -e "${post_dir}/${final_date}/${post_title_lower// /-}".html ]]; then
echo "ERROR: "${post_dir}/${final_date}/${post_title_lower// /-}".html already exists!."
exit 1
else
sleep 0
fi

# executes BASE_HTML fuction
BASE_HTML

# check if the directories and html were created correctly
if [[ -e "${post_dir}/${final_date}/${post_title_lower// /-}".html ]]; then

# add post link to blog.html
sed -i "/<ul class=\"${post_session_lower// /-}\">/a <li><article><a href=\"post\/${post_session_upper// /-}/${final_date}/${post_title_lower// /-}.html\" title=\"${post_title}\">${post_title} | <time datetime=\"${final_date_hour}\">${final_date}</time></a></article></li> " ${BLOGHTML}

# EDITOR
"${EDITOR}" "${post_dir}/${final_date}/${post_title_lower// /-}".html

# tags 
# TAG 1
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST-END:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag1_lower}.html
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag1_lower}.html
sed -i "/<\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->/a <li><article><a href=\"../post\/${post_session_upper// /-}/${final_date}/${post_title_lower// /-}.html\" title=\"${post_title}\">${post_title} | <time datetime=\"${final_date_hour}\">${final_date}</time></a></article></li>" ${DIR_TAGS}/tag_${tag1_lower}.html

# TAG 2
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST-END:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag2_lower}.html
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag2_lower}.html
sed -i "/<\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->/a <li><article><a href=\"../post\/${post_session_upper// /-}/${final_date}/${post_title_lower// /-}.html\" title=\"${post_title}\">${post_title} | <time datetime=\"${final_date_hour}\">${final_date}</time></a></article></li>" ${DIR_TAGS}/tag_${tag2_lower}.html

# TAG 3
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST-END:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag3_lower}.html
sed -i "/<!-- TAG -->/a <\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->" ${DIR_TAGS}/tag_${tag3_lower}.html
sed -i "/<\!-- SESSION:${post_session_upper// /-} - POST:${post_title_lower// /-} -->/a <li><article><a href=\"../post\/${post_session_upper// /-}/${final_date}/${post_title_lower// /-}.html\" title=\"${post_title}\">${post_title} | <time datetime=\"${final_date_hour}\">${final_date}</time></a></article></li>" ${DIR_TAGS}/tag_${tag3_lower}.html

echo "POST "${post_dir}/${final_date}/${post_title_lower// /-}".html CREATED SUCCESSFULLY!"
else
echo "ERROR: "${post_dir}/${final_date}/${post_title_lower// /-}".html NOT CREATED!"  
exit 1
fi

}

DEL_POST(){

CHECK_FILES

read -ep "Post session: " post_session

# variables
local post_session_upper="${post_session^^}"
local post_session_lower="${post_session,,}"

# check if session exists
if grep -qow '<ul class="'"${post_session_lower// /-}"'">' ${BLOGHTML} ; then
sleep 0
else
echo "ERROR: Session does not exist!."
exit 1
fi

# Year
read -p "Year: " year_post

# check if variable is null
if [[ -z "${year_post}" ]] ; then
echo "ERROR: name not specified"
exit 1
else
sleep 0
fi

# checks if the variable has only four digits
if [[ "${year_post}" = ?(+|-)+([0-9]) ]] && [[ "${#year_post}" -eq 4 ]] ; then 
sleep 0
else
echo "ERROR: value must be numeric and only have four digits"
exit 1
fi

# Month
read -ep "Month: " month_post

# check if variable is null
if [[ -z "${month_post}" ]] ; then
echo "ERROR: name not specified"
exit 1
else
sleep 0
fi

# checks if the variable has only two digits
if [[ "${month_post}" = ?(+|-)+([0-9]) ]] && [[ "${#month_post}" -eq 2 ]] ; then 
sleep 0
else
echo "ERROR: value must be numeric and only have two digits"
exit 1
fi

# Day
read -ep "Day: " day_post

# check if variable is null
if [[ -z "${day_post}" ]] ; then
echo "ERROR: name not specified"
exit 1
else
sleep 0
fi

read -ep "Post title: " post_title

# variables
local post_title_upper="${post_title^^}"
local post_title_lower="${post_title,,}"

# check if variable is null
if [[ -z "${post_title}" ]] ; then
echo "ERROR: name not specified"
exit 1
else
sleep 0
fi

# check if variable has special characters
if [[ "${post_title}" =~ ^[0-9A-Za-z\ ]+$ ]] && [[ "${new_session}" != *['!'@#\$%^ÀÈÌÒÙùòìèàÝÚÓÍÉÁýúóíéáÛÔÎÊÂûôîêâÕÑÃõñãŸÜÖÏËÄÿüöïëäÇç\&*()_+]* ]] ; then
sleep 0
else
echo "ERROR: has special characters"
exit 1
fi

# Checks if html file exists
if [[ -e "${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/${day_post}/${post_title_lower// /-}.html" ]] ; then
sleep 0
else
echo "ERROR: ${post_title_lower// /-}.html file does not exist!."
exit 1
fi

# checks if the variable has only two digits
if [[ "${day_post}" = ?(+|-)+([0-9]) ]] && [[ "${#day_post}" -eq 2 ]] ; then 
sleep 0
else
echo "ERROR: value must be numeric and only have two digits"
exit 1
fi

# asks if you want to delete the html file

read -p "Delete "${post_title_lower// /-}".html file??? [y/n]: " question

if [ "${question}" != "${question#[Yy]}" ] ;then
echo "Deleting ${post_title_lower// /-}"
sed -i '/<li><article><a href="post\/'"${post_session_upper// /-}"'\/'"${year_post}"'\/'"${month_post}"'\/'"${day_post}"'\/'"${post_title_lower// /-}"'.html" title=\"'"${post_title_lower}"'\">/d' ${BLOGHTML}
sed -i '/<\!-- SESSION:'"${post_session_upper// /-}"' - POST:'"${post_title_lower// /-}"' -->/,/<\!-- SESSION:'"${post_session_upper// /-}"' - POST-END:'"${post_title_lower// /-}"' -->/d' ${DIR_TAGS}/*.html
rm -vr "${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/${day_post}/${post_title_lower// /-}.html"
grep -rIL "<\!-- SESSION:.*" ${DIR_TAGS}/*.html 2>/dev/null | xargs rm -rv 2>/dev/null
else
echo "preserved "${post_title_lower// /-}".html file"
exit 0
fi

# delete the day directory if empty
if [ -z "$(ls -A ${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/${day_post}/)" ]; then
rmdir -v "${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/${day_post}/"
else
sleep 0 
fi

# delete the month directory if empty
if [ -z "$(ls -A ${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/)" ]; then
rmdir -v "${DIR_POST}/${post_session_upper// /-}/${year_post}/${month_post}/"
else
sleep 0
fi

# delete the year directory if empty
if [ -z "$(ls -A ${DIR_POST}/${post_session_upper// /-}/${year_post}/)" ]; then
rmdir -v "${DIR_POST}/${post_session_upper// /-}/${year_post}/"
else
sleep 0
fi
}

BROWSER(){
CHECK_FILES
x-www-browser "${INDEXHTML}"
}

HELP()
{
cat <<EOF
bashblog v1.0

This script creates a base for a website in html5, configure the variables in in double quotes, do not change the paths, the html files are created through the BASE_HTML fuction.

USAGE:
./bashblog [OPTIONS]

Arguments:
   -n
     Create necessary files and folders

   -s
     Adds new session
   
   -ds
     Delete session

   -p
     Adds new post to session

   -dp
     Delete post

   -b
     Opens website in browser

EOF
}

case $1 in
             "-n")  NEW            ;            ;;
             "-s")  ADD_SESSION      ;            ;;
             "-ds") DEL_SESSION      ;            ;;
             "-p")   ADD_POST      ;            ;;
             "-dp")   DEL_POST      ;            ;;
             "-b")   BROWSER         ;            ;;
                *)  HELP         ;  exit 1   ;   ;;
esac


Scripts recomendados

Checa Host

Shell Script / Perl para sincronizar base de usuários do AD com o Zimbra

Cálculo de raiz quadrada

Configurando IPTABLES de forma simples

script dapper para debootstrap


  

Comentários
[1] Comentário enviado por maurixnovatrento em 17/03/2021 - 21:56h


Muito Top.

___________________________________________________________
[code]Conhecimento não se Leva para o Túmulo.
https://github.com/MauricioFerrari-NovaTrento [/code]


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts