Comments (4)
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.
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.
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.
@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)
- Simplier count(*) HOT 2
- go/not-so-random.md HOT 1
- "List All The Say Voices" missorted HOT 2
- vim/scrolling-relative-to-the-window.md HOT 1
- JS: Truthiness of Integer Arrays HOT 1
- List filenames without the diffs HOT 1
- Move The Latest Commit To A New Branch HOT 1
- vim "Wrap With Some Room" precision HOT 4
- elixir/dynamically-generating-atoms is empty HOT 1
- postgres/turn-timing-on.md link is incorrect in README HOT 1
- Automate creation of README.md HOT 4
- Create RSS feed HOT 1
- Your newsletters go to spam
- vim-til: file name typo
- javascript/create-an-array-containing-1-to-n.md HOT 6
- sed: missing -n in example
- css: typo
- javascript/random-cannot-be-seeded.md HOT 1
- go/sleep-for-a-duration.md HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from til.