Giter Club home page Giter Club logo

Comments (4)

gnanet avatar gnanet commented on May 13, 2024 1

Made a short bash script, which creates a README.md into every category folder, if you execute it in the main TIL folder.

While testing, i found also a missing TIL:
https://github.com/jbranchaud/til/blob/master/vim/turning-off-search-highlighting.md

Better said, wrong link/filename (LOOK FOR THE MISSING F):
https://github.com/jbranchaud/til/blob/master/vim/turning-of-search-highlighting.md

It generates a simple TOC and then concatenates the markdown files in the order they appear in the main README.md, but it does not modify the original files:

#!/bin/bash

if [ -f README.md ]; then
    if [[ "$(head -n1 README.md)" == "# TIL" ]]; then
        subs=$(grep -oE "\(.*/.*\.md\)" README.md | tr -d ')(' | cut -d '/' -f1 | sort -u)

        for tilsub in ${subs}; do
            if [ ! -d ${tilsub} ]; then continue; fi
            echo "### Category ${tilsub}" > ${tilsub}/README.md
            echo "" >> ${tilsub}/README.md
            echo "---" >> ${tilsub}/README.md
            echo "" >> ${tilsub}/README.md
            tilfiles=$(grep -oE "\(${tilsub}/.*\.md\)" README.md | tr -d ')(')
            for tilfile in ${tilfiles}; do
                if [ ! -f ${tilfile} ]; then continue; fi
                titlestring=$(grep -E "^#" ${tilfile} | sed -e "s|^# ||g" | head -n1)
                titleanchor="#$(echo "${titlestring}" | sed -e "s/ /-/g" | tr '[:upper:]' '[:lower:]')"
                echo " - [${titlestring}](${titleanchor})" >> ${tilsub}/README.md
            done
            echo "" >> ${tilsub}/README.md
            echo "---" >> ${tilsub}/README.md
            echo "" >> ${tilsub}/README.md
            for tilfile in ${tilfiles}; do
                if [ ! -f ${tilfile} ]; then continue; fi
                cat ${tilfile} >> ${tilsub}/README.md
                echo "" >> ${tilsub}/README.md
            done
        done
    else
        echo "Not in main TIL folder"
        exit 1
    fi
else
    echo "Not in main TIL folder"
    exit 1
fi

from til.

gnanet avatar gnanet commented on May 13, 2024

Interesting idea, do you know if thats possible with pandoc not in Windows, and did you think about a way to add/modify the TOC links from the main readme?

I just looked around and found a relevant project:
https://github.com/knennigtri/merge-markdown

from til.

shoebham avatar shoebham commented on May 13, 2024

awesome man, just tried your script on GitHub actions works perfectly and fast (21s).

You can open a pull request and include this workflow and your script (named compile.sh for this workflow)

 # This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

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

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          echo "Compiling..."
          chmod +x ./compile.sh
          ./compile.sh
        
      - name: Commit and push changes
        run: |
          git config --global user.name "jbranchaud"
          git config --global user.email <email>
          git add -A
          git commit -m "combine files in a single README "
          git push

from til.

gnanet avatar gnanet commented on May 13, 2024

@shoebham just to make it a bit more candy, you could try this version, it generates a main README with links to the category single-page:

#!/bin/bash

if [ -f README.md ]; then
    if [[ "$(head -n1 README.md)" == "# TIL" ]]; then

        if [ -f README.orig.md ]; then
            cat README.orig.md > README.md
        else
            cat README.md > README.orig.md
        fi

        subs=$(grep -oE "\(.*/.*\.md\)" README.md | tr -d ')(' | cut -d '/' -f1 | sort -u)

        for tilsub in ${subs}; do
            if [ ! -d ${tilsub} ]; then continue; fi
            catorighead=$(grep -B2 "${tilsub}/" README.md | head -n1 | grep -E "^###")
            catheadstr=$(echo ${catorighead} | tr -d "#" | sed -e "s/^ //g")
            echo "# ${catheadstr} category" > ${tilsub}/README.md
            echo "" >> ${tilsub}/README.md
            tilfiles=$(grep -oE "\(${tilsub}/.*\.md\)" README.md | tr -d ')(')
            for tilfile in ${tilfiles}; do
                if [ ! -f ${tilfile} ]; then continue; fi
                titlestring=$(grep -E "^#" ${tilfile} | sed -e "s|^# ||g" | head -n1)
                titleanchor="#$(echo "${titlestring}" | sed -e "s/ /-/g" | tr '[:upper:]' '[:lower:]')"
                echo " - [${titlestring}](${titleanchor})" >> ${tilsub}/README.md
            done
            echo "" >> ${tilsub}/README.md
            echo "---" >> ${tilsub}/README.md
            echo "" >> ${tilsub}/README.md
            for tilfile in ${tilfiles}; do
                if [ ! -f ${tilfile} ]; then continue; fi
                cat ${tilfile} >> ${tilsub}/README.md
                echo "" >> ${tilsub}/README.md
            done
        done
        for tilsub in ${subs}; do
            if [ ! -d ${tilsub} ]; then continue; fi
            catorighead=$(grep -B2 "${tilsub}/" README.md | head -n1 | grep -E "^###")
            catheadstr=$(echo ${catorighead} | tr -d "#" | sed -e "s/^ //g")
            sed -i -e "s|^${catorighead}$|${catorighead}\n\n**\[${catheadstr} category as single-page\]\(${tilsub}/README.md\)**|g" README.md
        done
    else
        echo "Not in main TIL folder"
        exit 1
    fi
else
    echo "Not in main TIL folder"
    exit 1
fi

from til.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.