diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..63a5e88 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,26 @@ +name: Build-blog +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + - name: Install requirements and build + run: | + pip install -r requirements.txt + python3 ./code/build.py + ls ./_build + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.PAT_BLOG }} + publish_dir: ./_build diff --git a/.gitignore b/.gitignore index 90df1e3..104928d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ # Distribution / packaging .Python build/ +_build/ develop-eggs/ dist/ downloads/ diff --git a/README.md b/README.md index 5cf5c6c..d01154e 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,41 @@ # BrainDataScienceBlog This is a repository with the code and raw materials to build the [*Brain, Data, and Science*](http://diedrichsenlab.org/BrainDataScience) Blog. It is heavily build on the [Tufte.css](https://edwardtufte.github.io/tufte-css/) and the [markdown library](https://python-markdown.github.io/). -## Installation +## Automatic GH-pages deployment + +### Step-0 Fork this repository ⑂ + +### Step-1 Create a GitHub access token 🔑 + +Please follow [these instructions](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token#creating-a-token) to create an access token. While creating the token, you will only click the `repository` checkbox. + +### Step-2 Create an encrypted secret for your repo 😎 + +Simply follow [these steps](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository) to create a **repository secret named `PAT_BLOG`**. + +### Step-3 That's it! + +If a secret is added successfully, a webpage build will be run by GitHub actions automatically and the webpage will be published online at: `your_gh_user_name.github.io/BrainDataScienceBlog` (unless you change the repository name). + +You can test the build by simply changing the README file (remove the last line etc.). When you add more content following the [writing a new blog section](#writing-a-new-blog), those pages will be built automatically and added to your webpage! + +## Local Installation Fork or clone the [GitHub repository](https://github.com/DiedrichsenLab/BrainDataScienceBlog). -The repro required `python v >= 3.8`. You also need to have the following dependencies installed: +The repro required `python v >= 3.6`. You also need to have the following dependencies installed: ``` -pip install markdown -pip install xml -pip install yaml -pip install pandas -pip install shutil -pip intall pybtex +pip install -r requirements.txt ``` -## Building the webpage +## Building the webpage manually + +A single Markdown file can be compiled to the target (`_build`) directory using: -A single Markdown file can be compiled to the target directory using: +`python3 ./code/build.py` -`python3 build.py` +If the build succeeds, you can see the webpage by opening `_build/index.htm` in your web browser. ## Writing a new blog diff --git a/code/build.py b/code/build.py index c9c99dc..69d548c 100644 --- a/code/build.py +++ b/code/build.py @@ -8,11 +8,11 @@ import shutil # Source directory is the repository based -sourceDir = os.path.dirname(os.path.dirname(__file__)) +sourceDir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),'..')) # Build directory can be set here optionally - defaults to html in repository -buildDir = '/Users/jdiedrichsen/Dropbox (Diedrichsenlab)/Sites/Diedrichsenlab/BrainDataScience' +buildDir = os.path.join(sourceDir,'_build') if not os.path.exists(buildDir): - buildDir = os.path.join(sourceDir,'html') + buildDir = os.path.join(sourceDir,'_build') if not os.path.exists(buildDir): os.makedirs(buildDir) @@ -121,7 +121,8 @@ def main(): shutil.copy2(source,target) # Build all the blogs in the list - with open("list.yaml", "r", encoding="utf-8") as list_file: + ymlFile = os.path.join(sourceDir,'list.yaml') + with open(ymlFile, "r", encoding="utf-8") as list_file: listing = yaml.load(list_file,Loader=yaml.FullLoader) info = [] for blog in listing['blogs']: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d181a6e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +markdown +markdown-include +xml-python +pyyaml +pandas +pybtex \ No newline at end of file