All Blog Posts
1. Overview
This page is a list of all blog posts on the site. It is created using literate programming in an Org File (albeit by a literate programming beginner). That pulls all files from a directory (and not directories), checks for html extention (really just 'l' for now), then converts to an Org mode links (so that I can export to html easier, which you are reading on).
- [+] List completed - # of files: 69
- [+] # of HTML files: 30
- [+] Converted 30 files into 30 valid links
- 2022-11-22 emacs learnings
- 2023-01-08 installing spellcheck emacs
- 2023-07-21 hacker mindset
- 2023-07-15 emacs tramp and local vms
- 2022-11-29 security tools
- 2022-11-23 Haskell LP Budget
- 2022-12-05 learning nim
- 2022-11-21 interactive code
- 2023-01-09 Looking into the new year
- 2022-11-03 haskell first steps
- 2022-05-25 basic ad enum on wire
- 2022-11-20 taking on emacs
- 2024-01-30 web security fundamentals
- 2022-12-09 nim encryption
- 2022-11-01 blogkickoff
- 2023-01-24 pivot lab setup
- 2022-11-24 thanksgiving update
- 2023-02-09 python subcommands
- 2022-03-13 cyber news of week
- 2022-11-28 budget template p3
- 2022-11-27 budget template p2
- 2022-03-06 cyber news of week
- 2023-07-22 backup script
- 2022-11-04 state of progress
- 2022-11-02 basic functional arguments
- 2023-01-25 ansible learnings
- 2022-11-26 revisiting dockworker
- 2023-02-02 pivoting
- 2022-11-25 publishing with org
- 2022-11-30 november recap
2. Write a python script that prints out all files as a result
Modified from Stack Overflow Answer on How do I list all files of a directory. I set the path to the local path since that is where all of the blogs posts are stored. This should filter out any directories that may exist in the future.
from os import listdir from os.path import isfile, join mypath = "./" onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] ## enter length of directory! print("- [+] List completed - # of files: {}".format(len(onlyfiles)))
- [+] List completed - # of files: 69
3. Take this list and filter on for *.html files
While the 'l'
in html may not be the only extention that ends with 'l'
in existence. It is good enough for my personal blog. The risk of a potential inclusion with another extension that ends in 'l'
is acceptable. This is similar to the risk I'm accepting with only parsing for dates at the beginning, and exluding this file starting with 'a'
.
htmlList = [] for line in onlyfiles: if (line[-1] == 'l') and (line[0] != 'a'): htmlList.append(line) print("- [+] # of HTML files: {}".format(len(htmlList)))
- [+] # of HTML files: 30
4. Convert html files to org links
blogPostLinks = [] for line in htmlList: getDate = line[:10] getTitle = line[11:-5] cleanTitle = getTitle.replace("-", " ") orgLink = "- [[file:./" + line + "][" + getDate + " " + cleanTitle + "]]" blogPostLinks.append(orgLink) print("- [+] Converted {} files into {} valid links".format(len(htmlList), len(blogPostLinks)))
- [+] Converted 30 files into 30 valid links
5. The Final Code
Note, the actual code block below has been modified to show the text that the header will execute. You should be able to recreate using the visual header below, and the code below, along with all of the code block (except Overview) above, named how they are named between the <<import-here>>
in order.
#+BEGIN _SRC python :results output raw :exports results :noweb yes :tangle yes
<<file-list>> <<html-filter>> <<org-links>> for line in blogPostLinks: print(line)
Then what it would look like if from if you exported the above blog into a webpage with :exports code
instead of the current header of :exports results
from os import listdir from os.path import isfile, join mypath = "./" onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] ## enter length of directory! print("- [+] List completed - # of files: {}".format(len(onlyfiles))) htmlList = [] for line in onlyfiles: if (line[-1] == 'l') and (line[0] != 'a'): htmlList.append(line) print("- [+] # of HTML files: {}".format(len(htmlList))) blogPostLinks = [] for line in htmlList: getDate = line[:10] getTitle = line[11:-5] cleanTitle = getTitle.replace("-", " ") orgLink = "- [[file:./" + line + "][" + getDate + " " + cleanTitle + "]]" blogPostLinks.append(orgLink) print("- [+] Converted {} files into {} valid links".format(len(htmlList), len(blogPostLinks))) for line in blogPostLinks: print(line)