github 블로그 만들기 - 쥬피터(jupyter) 파일 자동 업로드 세팅

oneofakindscene·2021년 2월 7일
0

github

목록 보기
3/7

쥬피터 파일 자동 업로드 세팅

  • 아래 과정을 자동으로 할 수 있는 함수를 만들어서 활용하는 방안
  • jupyter 파일 ⇒ markdown 파일 변환 후 ⇒ github에 업로드
    • 이미지 파일도 함께 업로드 해주도록 함수가 만들어짐
    • 설정한 값으로 FRONT_MATTER가 적히도록 만들어짐
  • 아래 new_post 함수 ⇒ .zshrc 혹은 .bashrc에 아래 code 추가 => 추가 후 shell에서 source ~/.zshrc 해줘야 적용됨
  • new_post [파일명.ipnyb] [post제목] [post카테고리]
function new_post {
    GH_USER="[Github ID]"  # GitHub ID
    PC_USER="[현재컴퓨터호스트명]"
    # 아래path예시로 보여준 것이고 본인이 설정한path로 설정
    POST_PATH = "/home/[사용자]/[테마설치한최상위폴더경로]/[github아이디 or 주소].github.io/_posts" 
    IMG_PATH = "/home/[사용자]/[테마설치한최상위폴더경로]/[github아이디 or 주소].github.io/images"  
		
    # "$1"은 첫번째 input parameter를 뜻함
    # 아래 변수들은 markdown파일 제일앞에 들어가야하는 필수요소 FRONT_MATTER설정에 필요함
    FILE_NAME="$1"
    LAYOUT="post"
    TITLE="$2"
    AUTHOR="SCENE"
    POST_DATETIME_NAME=`date "+%Y-%m-%dT%H:%M:%S"`
    CURR_DIR=`pwd`
    FILE_BASE=`basename $FILE_NAME .ipynb`

		
    CATEGORY="$3"
    if [ ! -n "$CATEGORY" ]
    then
				# CATEGORY default값으로 DATA로 설정하였음
        CATEGORY="DATA"
    else
        CATEGORY="$3"
    fi
    FRONT_MATTER="---
layout: "$LAYOUT"
title: "$TITLE"
date: "$POST_DATETIME_NAME"
author: "$AUTHOR"
categories: "$CATEGORY"
---"

    POST_NAME="${FILE_BASE}.md"
    IMG_NAME="${FILE_BASE}_files"

    POST_DATE_NAME=`date "+%Y-%m-%d-"`${POST_NAME}

    # convert the notebook
    jupyter nbconvert --to markdown $FILE_NAME

		# 맨앞에 front matter 붙여주는 코드
    echo -e "$FRONT_MATTER\n$(cat $FILE_BASE.md)" > $FILE_BASE.md

    # 마크다운에서 이미지삽입된 부분 올바른 경로로 수정해주는 코드
		sed -i "s:\[png\](:[png](/images/:" $POST_NAME
    
		# move everything to blog area
    mv  $POST_NAME "${POST_PATH}/${POST_DATE_NAME}"
    mv  $IMG_NAME "${IMG_PATH}/"

    # add files to git repo to be included in next commit
    cd $POST_PATH
    git add $POST_DATE_NAME
    cd $IMG_PATH
    git add $IMG_NAME

    # make git submission
    cd ..
    git commit -m "\"New blog entry ${FILE_BASE}\""

    # push changes to server
    git push

    cd $CURR_DIR
}

dataframe 보기좋게 나올 수 있도록 세팅하기

<!DOCTYPE html>
<html>
	<head>
	<!-- Begin section for dataframe table formatting -->
	<style type="text/css">
	table.dataframe {
         width: 100%;
         height: 240px;
         display: block;
         overflow: auto;
         font-family: Arial, sans-serif;
         font-size: 13px;
         line-height: 20px;
         text-align: center;
     }
     table.dataframe th {
       font-weight: bold;
       background: #d3d3d3;
       padding: 4px;
     }
     table.dataframe td {
       padding: 4px;
     }
     table.dataframe tr:hover {
       background: #b8d1f3;
     }
     </style>
     <!-- End section for dataframe table formatting -->

     </head>
 
     {% include head.html %}
 
     <body>
 
     {% include header.html %}

         <div class="page-content">
                    {{ content }}
         </div>

     {% include footer.html %}

     </body>

     </html>
profile
oneofakindscene

0개의 댓글