[2024-06-21 Fri] Major changes to the code
This commit is contained in:
parent
be3306aac2
commit
dc31e6399c
24 changed files with 500 additions and 279 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
/cosmicpirates.space-gmi/
|
/public/
|
||||||
/cosmicpirates.space-html/
|
/.packages/
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
|-
|
|
||||||
|Title|Last Modified|Created|
|
|
||||||
|-
|
|
||||||
|[[file:./blogs/test_blog_3.org][Test Blog]]||[2024-02-05 Thu]|
|
|
|
@ -17,8 +17,8 @@
|
||||||
: +-------------------------------------------+
|
: +-------------------------------------------+
|
||||||
#+end_center
|
#+end_center
|
||||||
|
|
||||||
#+name: link-list.txt
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
: +--------------------------------------+
|
: +--------------------------------------+
|
||||||
#+end_center
|
#+end_center
|
||||||
|
|
||||||
#+name: link-list.txt
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
|
|
||||||
We think that knowledge should be open to everyone and freely accessible.
|
We think that knowledge should be open to everyone and freely accessible.
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
* A list of All Blogs
|
* A list of All Blogs
|
||||||
|
|
||||||
#+name: blog-table-complete.txt
|
#+name: blog-table-complete
|
||||||
|-
|
|-
|
||||||
|Title|Last Modified|Created|
|
|Title|Last Modified|Created|
|
||||||
|-
|
|-
|
|
@ -11,10 +11,10 @@
|
||||||
#+end_center
|
#+end_center
|
||||||
|
|
||||||
|
|
||||||
#+name: link-list.txt
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
|
|
||||||
* Dibyashanu Pati
|
* Dibyashanu Pati
|
|
@ -13,16 +13,9 @@
|
||||||
: +------------------------------------------------------------------------------------------------------------------------+
|
: +------------------------------------------------------------------------------------------------------------------------+
|
||||||
#+end_center
|
#+end_center
|
||||||
|
|
||||||
#+name: link-list.txt
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
* Latest Blogs
|
|
||||||
Here is a list of our latest blog posts
|
|
||||||
|
|
||||||
#+name: blog-table-latest-10.txt
|
|
||||||
|-
|
|
||||||
|Title|Last Modified|Created|
|
|
||||||
|-
|
|
||||||
|[[file:./blogs/test_blog_3.org][Test Blog]]||[2024-02-05 Thu]|
|
|
|
@ -28,10 +28,10 @@
|
||||||
: +------------------------------------------+
|
: +------------------------------------------+
|
||||||
#+end_center
|
#+end_center
|
||||||
|
|
||||||
#+name: link-list.txt
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
#+TOC: headlines 1
|
#+TOC: headlines 1
|
||||||
|
|
||||||
|
@ -42,9 +42,4 @@ https://cosmicpirates.space/
|
||||||
|
|
||||||
** TOR
|
** TOR
|
||||||
#+name: tor-onionv3-address.txt
|
#+name: tor-onionv3-address.txt
|
||||||
http://acfc2abqv65bdiwimrx74vrlxy6eel66cjlmgqqvdekcrx7ufl3c2cad.onion
|
Not found
|
||||||
|
|
||||||
|
|
||||||
** I2P
|
|
||||||
#+name: i2p-b32-address.txt
|
|
||||||
http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p
|
|
24
content/news.org
Normal file
24
content/news.org
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#+title: News
|
||||||
|
#+created: [2024-03-01 Fri]
|
||||||
|
#+last_modified: [2024-03-06 Wed]
|
||||||
|
#+setupfile: main.setup
|
||||||
|
|
||||||
|
#+begin_center
|
||||||
|
: +--------------------------------------+
|
||||||
|
: | _ _ |
|
||||||
|
: | | \ | | ___ __ __ ___ |
|
||||||
|
: | | \| | / _ \ \ \ /\ / / / __| |
|
||||||
|
: | | |\ | | __/ \ V V / \__ \ |
|
||||||
|
: | |_| \_| \___| \_/\_/ |___/ |
|
||||||
|
: +--------------------------------------+
|
||||||
|
#+end_center
|
||||||
|
|
||||||
|
#+name: link-list
|
||||||
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
|
* TOR and I2P - [2024-03-06 Wed]
|
||||||
|
Went live on I2P
|
||||||
|
#+name: i2p-b32-address.txt
|
||||||
|
Not found
|
81
create-site.el
Normal file
81
create-site.el
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
;; Set the package installation directory so that packages aren't stored in the
|
||||||
|
;; ~/.emacs.d/elpa path.
|
||||||
|
(require 'package)
|
||||||
|
(setq package-user-dir (expand-file-name "./.packages"))
|
||||||
|
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
|
||||||
|
("elpa" . "https://elpa.gnu.org/packages/")))
|
||||||
|
|
||||||
|
;; Initialize the package system
|
||||||
|
(package-initialize)
|
||||||
|
(unless package-archive-contents
|
||||||
|
(package-refresh-contents))
|
||||||
|
|
||||||
|
;; Install dependencies
|
||||||
|
(package-install 'htmlize)
|
||||||
|
(package-install 'ox-gemini)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; Load the publishing system
|
||||||
|
(require 'ox-publish)
|
||||||
|
(use-package ox-gemini)
|
||||||
|
|
||||||
|
|
||||||
|
(setq org-publish-use-timestamps-flag nil)
|
||||||
|
(setq org-html-validation-link nil
|
||||||
|
org-html-head-include-scripts nil
|
||||||
|
org-html-head-include-default-style nil
|
||||||
|
org-html-preamble nil
|
||||||
|
org-html-postamble nil
|
||||||
|
org-html-use-infojs nil
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
(setq org-publish-project-alist '(
|
||||||
|
("cosmicpirates-html"
|
||||||
|
:base-directory "./content"
|
||||||
|
:base-extension "org"
|
||||||
|
:publishing-directory "public/cosmicpirates.space-html"
|
||||||
|
:recursive t
|
||||||
|
:publishing-function org-html-publish-to-html
|
||||||
|
;;:with-author nil
|
||||||
|
;;:with-creator nil
|
||||||
|
;;:email nil
|
||||||
|
:with-timestamps nil
|
||||||
|
)
|
||||||
|
|
||||||
|
("cosmicpirates-html-static"
|
||||||
|
:base-directory "./content/static"
|
||||||
|
:base-extension "css\\|ttf\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|mp4\\|xml\\|html"
|
||||||
|
:publishing-directory "./public/cosmicpirates.space-html/static"
|
||||||
|
:recursive t
|
||||||
|
:publishing-function org-publish-attachment
|
||||||
|
)
|
||||||
|
|
||||||
|
("cosmicpirates-gmi"
|
||||||
|
:base-directory "./content"
|
||||||
|
:base-extension "org"
|
||||||
|
:publishing-directory "./public/cosmicpirates.space-gmi"
|
||||||
|
:recursive t
|
||||||
|
:publishing-function org-gemini-publish-to-gemini
|
||||||
|
:with-author nil
|
||||||
|
:with-creator nil
|
||||||
|
:email nil
|
||||||
|
:with-timestamps nil
|
||||||
|
)
|
||||||
|
|
||||||
|
("cosmicpirates-gmi-static"
|
||||||
|
:base-directory "./content/static"
|
||||||
|
:base-extension "css\\|ttf\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|xml\\|html"
|
||||||
|
:publishing-directory "./public/cosmicpirates.space-gmi/static"
|
||||||
|
:recursive t
|
||||||
|
:publishing-function org-publish-attachment
|
||||||
|
export txt file as txt file in org html website publish
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
;; publish the websites
|
||||||
|
(org-publish-all t)
|
||||||
|
|
||||||
|
(message "Build complete!")
|
13
create.sh
Executable file
13
create.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# update addresses
|
||||||
|
python scripts/generate_and_update_address_files.py
|
||||||
|
|
||||||
|
#Add headings links to all top level files
|
||||||
|
python scripts/heading-link-generator.py
|
||||||
|
|
||||||
|
# Generate the main blog table
|
||||||
|
python scripts/blog-table-generator.py
|
||||||
|
|
||||||
|
# generate the html and gemini versions of the site using org-publish
|
||||||
|
emacs -Q --script create-site.el
|
|
@ -1,3 +0,0 @@
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|
254
main.org
254
main.org
|
@ -3,18 +3,13 @@
|
||||||
|
|
||||||
* Usage Instructions and Best Practices
|
* Usage Instructions and Best Practices
|
||||||
** Basic Plan
|
** Basic Plan
|
||||||
+ The entire organization of the website is generated by the scripts in this file.
|
+ The entire organization of the website is generated by the +scripts in this file+ scripts in the [[file:scripts/]] directory.
|
||||||
+ These scripts generated org files which are later published in other formats
|
+ These scripts generated by this file.
|
||||||
|
+ To run the scripts in [[file:scripts/]] and to generate the website just run [[file:create.sh]]
|
||||||
|
|
||||||
** TODO Software and tools
|
** Software and tools
|
||||||
|
+ python
|
||||||
+ [[https://www.gnu.org/software/emacs/][Emacs]]
|
+ [[https://www.gnu.org/software/emacs/][Emacs]]
|
||||||
+ [[https://github.com/doomemacs/doomemacs][doomemacs]]
|
|
||||||
** How to use this file
|
|
||||||
This file contains all the information for the website and updating the website consist of the following steps
|
|
||||||
1. Run all scripts on this page by running org-babel-execut-buffer(C-c C-v b)
|
|
||||||
2. Publish the Project org-Publish (SPC-m P p)
|
|
||||||
3. Check the local copy of the website
|
|
||||||
4. If sure sync the local copy with the server copy
|
|
||||||
** Advice
|
** Advice
|
||||||
+ Do not use the #+include tag
|
+ Do not use the #+include tag
|
||||||
Writing dynamic content to files and then using #+include to include them in other files has unreliable link conversion
|
Writing dynamic content to files and then using #+include to include them in other files has unreliable link conversion
|
||||||
|
@ -258,10 +253,9 @@ o888bood8P' o888o `Y8bod8P' `8oooooo. 8""888P'
|
||||||
None
|
None
|
||||||
#+end_example
|
#+end_example
|
||||||
|
|
||||||
|
|
||||||
** File Read Write functions
|
** File Read Write functions
|
||||||
*** Write in the place with a given #+name tag
|
*** Write in the place with a given #+name tag
|
||||||
#+begin_src python
|
#+begin_src python :results silent
|
||||||
def write_output_to_org_file(file_path, name, output):
|
def write_output_to_org_file(file_path, name, output):
|
||||||
with open(file_path, 'r') as file:
|
with open(file_path, 'r') as file:
|
||||||
data = file.readlines()
|
data = file.readlines()
|
||||||
|
@ -275,9 +269,6 @@ def write_output_to_org_file(file_path, name, output):
|
||||||
file.write(line)
|
file.write(line)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+RESULTS:
|
|
||||||
: None
|
|
||||||
|
|
||||||
*** Read txt files
|
*** Read txt files
|
||||||
#+begin_src python
|
#+begin_src python
|
||||||
def read_file(file_path):
|
def read_file(file_path):
|
||||||
|
@ -294,22 +285,21 @@ def read_file(file_path):
|
||||||
|
|
||||||
|
|
||||||
* Administrative-scripts
|
* Administrative-scripts
|
||||||
:PROPERTIES:
|
|
||||||
:EXPORT_EXCLUDE_TAGS: noexport
|
|
||||||
:END:
|
|
||||||
** Blogs
|
** Blogs
|
||||||
*** Main Blog list
|
*** Main Blog list
|
||||||
**** Generate Main blog list for [[file:blogs/blog-list.org]]
|
:PROPERTIES:
|
||||||
The following script looks at all org files(except [[blogs/Blog-list.org][blog-list.org]]) in the [[file:blogs]] directory and finds there title, creation date, and last modified date and then displays it in the file in the form of a org table then this table is exported to [[Blogs/blog-table-complete.org]] which ultimately included in [[Blog/Blog-list.org]].
|
:HEADER-ARGS: python :tangle scripts/blog-table-generator.py :comments both
|
||||||
This could also have been done using the :results_switches parameter but then the result text would have to be in python(ie the same language as the generating block) so instead I used the elisp block [[file:::blog-list-table-result-writer]].
|
:END:
|
||||||
|
**** Generate Main blog list for [[file:content/blogs/blog-index.org]]
|
||||||
|
The following code block looks at all org files(except [[file:content/blogs/blog-index.org]] ) in the [[file:content/blogs/]] directory and finds there title, creation date, and last modified date and then creates an org table, then this table is stored as a string in the blog_table variable
|
||||||
# begin_src python :results output raw :exports results
|
# begin_src python :results output raw :exports results
|
||||||
#+name: blog-table-generator
|
#+name: blog-table-generator
|
||||||
#+begin_src python :results output raw :exports none
|
#+begin_src python
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# path of the blog directory
|
# path of the blog directory
|
||||||
blogs_directory = "./blogs/"
|
blogs_directory = "./content/blogs"
|
||||||
|
|
||||||
|
|
||||||
# get a list of all things in blogs_directory
|
# get a list of all things in blogs_directory
|
||||||
|
@ -319,16 +309,19 @@ max_lines_to_scan = 10
|
||||||
#Only include files which are .org and do no include the main Blog-list.org file which serves as an index
|
#Only include files which are .org and do no include the main Blog-list.org file which serves as an index
|
||||||
b = []
|
b = []
|
||||||
for i in range(0,len(blog_list)):
|
for i in range(0,len(blog_list)):
|
||||||
if blog_list[i].endswith(".org") and blog_list[i] != 'blog-list.org':
|
if blog_list[i].endswith(".org") and blog_list[i] != 'blog-index.org':
|
||||||
b.append(blog_list[i])
|
b.append(blog_list[i])
|
||||||
blog_list=b
|
blog_list=b
|
||||||
|
|
||||||
#Sort blog files by last modified time
|
#Sort blog files by last modified time
|
||||||
# blog_list.sort(key=lambda x: os.path.getmtime(blogs_directory+x),reverse=True)
|
# blog_list.sort(key=lambda x: os.path.getmtime(blogs_directory+x),reverse=True)
|
||||||
|
|
||||||
|
# variable to store output table
|
||||||
|
blog_table = ""
|
||||||
|
|
||||||
#prints the heading of the list.
|
#prints the heading of the list.
|
||||||
print("|-")
|
blog_table += ("|-\n")
|
||||||
print("|Title|Last Modified|Created|")
|
blog_table += ("|Title|Last Modified|Created|\n")
|
||||||
|
|
||||||
titles = []
|
titles = []
|
||||||
title_found = False
|
title_found = False
|
||||||
|
@ -336,6 +329,7 @@ creation_dates = []
|
||||||
creation_found = False
|
creation_found = False
|
||||||
last_modified_found = False
|
last_modified_found = False
|
||||||
last_modified_dates = []
|
last_modified_dates = []
|
||||||
|
|
||||||
# finds the title, last modified time and creation time
|
# finds the title, last modified time and creation time
|
||||||
for blog_no in range(0,len(blog_list)):
|
for blog_no in range(0,len(blog_list)):
|
||||||
with open(blogs_directory +'/'+ blog_list[blog_no], "r") as file:
|
with open(blogs_directory +'/'+ blog_list[blog_no], "r") as file:
|
||||||
|
@ -364,7 +358,7 @@ for blog_no in range(0,len(blog_list)):
|
||||||
creation_dates.append('unknown')
|
creation_dates.append('unknown')
|
||||||
if title_found == False:
|
if title_found == False:
|
||||||
titles.append('unknown')
|
titles.append('unknown')
|
||||||
print("|-")
|
blog_table += ("|-\n")
|
||||||
|
|
||||||
def sort_multiple_lists(*args):
|
def sort_multiple_lists(*args):
|
||||||
"""This function sorts multiple lists according to the sorting of the first list and returns the sorted lists as a tuple"""
|
"""This function sorts multiple lists according to the sorting of the first list and returns the sorted lists as a tuple"""
|
||||||
|
@ -382,39 +376,15 @@ def sort_multiple_lists(*args):
|
||||||
# Extract the sorted lists and return them
|
# Extract the sorted lists and return them
|
||||||
return(list(zip(*sorted_tuples_list)))
|
return(list(zip(*sorted_tuples_list)))
|
||||||
|
|
||||||
# print((creation_dates,last_modified_dates,blog_list))
|
|
||||||
|
|
||||||
# Sort all lists according to creation_date
|
# Sort all lists according to creation_date
|
||||||
sorted_creation_dates,sorted_titles,sorted_last_modified_dates,sorted_blog_list = sort_multiple_lists(creation_dates,titles,last_modified_dates,blog_list)
|
sorted_creation_dates,sorted_titles,sorted_last_modified_dates,sorted_blog_list = sort_multiple_lists(creation_dates,titles,last_modified_dates,blog_list)
|
||||||
|
|
||||||
# print((creation_dates,last_modified_dates,blog_list))
|
|
||||||
# creation_dates,blog_list= zip(*sorted(zip(creation_dates,blog_list),reverse = True))
|
|
||||||
|
|
||||||
#prints the rest of the list
|
|
||||||
for blog_no in range(0,len(blog_list)):
|
for blog_no in range(0,len(blog_list)):
|
||||||
print( "|"+ '[[file:'+ sorted_blog_list[blog_no]+ ']' + '['+sorted_titles[blog_no] + ']]'+ '|' +sorted_last_modified_dates[blog_no] + '|' + sorted_creation_dates[blog_no] + '|')
|
blog_table += ("|"+ '[[file:'+ sorted_blog_list[blog_no]+ ']' + '['+sorted_titles[blog_no] + ']]'+ '|' +sorted_last_modified_dates[blog_no] + '|' + sorted_creation_dates[blog_no] + '|\n')
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
**** Write the blog table into [[file:content/blogs/blog-index.org]]
|
||||||
#+RESULTS: blog-table-generator
|
#+begin_src python
|
||||||
|-
|
|
||||||
|Title|Last Modified|Created|
|
|
||||||
|-
|
|
||||||
|[[file:test_blog_3.org][Test Blog]]||[2024-02-05 Thu]|
|
|
||||||
|
|
||||||
**** Write the main blog list in [[file:blogs/blog-table-complete.txt]]
|
|
||||||
The snippet below writes the table above to a text file [[file:blogs/blog-table-complete.txt]]
|
|
||||||
#+name: blog-list-table-result-writer
|
|
||||||
#+begin_src emacs-lisp :results silent
|
|
||||||
(save-excursion
|
|
||||||
(org-babel-goto-named-result "blog-table-generator")
|
|
||||||
(forward-line)
|
|
||||||
(write-region (point) (org-babel-result-end) "blogs/blog-table-complete.txt")
|
|
||||||
)
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
**** Read and write the main blog list into [[file:blogs/blog-list.org]]
|
|
||||||
#+begin_src python :results silent
|
|
||||||
def write_output_to_org_file(file_path, name, output):
|
def write_output_to_org_file(file_path, name, output):
|
||||||
erase_until_newline_after_name(file_path)
|
erase_until_newline_after_name(file_path)
|
||||||
with open(file_path, 'r') as file:
|
with open(file_path, 'r') as file:
|
||||||
|
@ -445,146 +415,26 @@ def erase_until_newline_after_name(filename):
|
||||||
else:
|
else:
|
||||||
file.write(line)
|
file.write(line)
|
||||||
|
|
||||||
def read_file(file_path):
|
write_output_to_org_file( "content/blogs/blog-index.org", "blog-table-complete", blog_table)
|
||||||
try:
|
|
||||||
with open(file_path, 'r') as file:
|
|
||||||
file_contents = file.read()
|
|
||||||
return file_contents
|
|
||||||
except FileNotFoundError:
|
|
||||||
return "Not found"
|
|
||||||
|
|
||||||
write_output_to_org_file( "blogs/blog-list.org", "blog-table-complete.txt", read_file('blogs/blog-table-complete.txt'))
|
|
||||||
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*** Latest Blogs
|
|
||||||
**** Generating a list of 10 latest blogs
|
|
||||||
This snippet just extracts the first 10 lines from file:blogs/blog-table-complete.txt
|
|
||||||
#+name: latest-10-blog-table-generator
|
|
||||||
#+begin_src python :results output raw :exports none
|
|
||||||
def extract_first_n_lines(file_path, n: int):
|
|
||||||
"""Helper function to extract n lines from a text file"""
|
|
||||||
lines =[]
|
|
||||||
with open(file_path,'r') as file:
|
|
||||||
for _ in range(n):
|
|
||||||
line = file.readline().rstrip('\n')
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
lines.append(line)
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def prepend_path_to_links(string,path):
|
|
||||||
"""This is a helper function which fixes the relative file paths in a string"""
|
|
||||||
import re
|
|
||||||
|
|
||||||
# pattern to match file links
|
|
||||||
pattern = r'\[\[.*?\]'
|
|
||||||
|
|
||||||
# find all links
|
|
||||||
org_links = re.findall(pattern,string)
|
|
||||||
|
|
||||||
for org_link in org_links:
|
|
||||||
# Extract the path from the org link
|
|
||||||
path_retgx = r'\[\[(.*?)\]'
|
|
||||||
path_match = re.search(path_retgx,org_link)
|
|
||||||
if path_match:
|
|
||||||
current_path = path_match.group(1)
|
|
||||||
|
|
||||||
# Prepend the provided path to the current path
|
|
||||||
new_path = '{}{}'.format(path,current_path)
|
|
||||||
|
|
||||||
# Repalace the old path with the new path in the org link
|
|
||||||
updated_org_link = org_link.replace(current_path,new_path)
|
|
||||||
|
|
||||||
#Return the replaced string
|
|
||||||
return(string.replace(org_link,updated_org_link))
|
|
||||||
|
|
||||||
|
|
||||||
list_of_output_lines=extract_first_n_lines("blogs/blog-table-complete.txt",13)
|
|
||||||
|
|
||||||
for line in list_of_output_lines:
|
|
||||||
line = line.replace('file:','')
|
|
||||||
modified_line = prepend_path_to_links(line,"file:./blogs/")
|
|
||||||
if modified_line == None:
|
|
||||||
print(line)
|
|
||||||
else:
|
|
||||||
print(modified_line)
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+RESULTS: latest-10-blog-table-generator
|
|
||||||
|-
|
|
||||||
|Title|Last Modified|Created|
|
|
||||||
|-
|
|
||||||
|[[file:./blogs/test_blog_3.org][Test Blog]]||[2024-02-05 Thu]|
|
|
||||||
|
|
||||||
**** Write the latest 10 blogs in a txt file
|
|
||||||
Write the above result to [[file:blog-table-latest-10.txt]]
|
|
||||||
#+name: latest-10-blog-table-result-writer
|
|
||||||
#+begin_src emacs-lisp :results silent
|
|
||||||
(save-excursion
|
|
||||||
(org-babel-goto-named-result "latest-10-blog-table-generator")
|
|
||||||
(forward-line)
|
|
||||||
(write-region (point) (org-babel-result-end) "blog-table-latest-10.txt")
|
|
||||||
)
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
**** Read and write the latest 10 blogs table in [[file:index.org]]
|
|
||||||
#+begin_src python :results silent
|
|
||||||
def write_output_to_org_file(file_path, name, output):
|
|
||||||
erase_until_newline_after_name(file_path,name)
|
|
||||||
with open(file_path, 'r') as file:
|
|
||||||
data = file.readlines()
|
|
||||||
|
|
||||||
with open(file_path, 'w') as file:
|
|
||||||
for line in data:
|
|
||||||
if '#+name: ' in line and name in line:
|
|
||||||
file.write(line)
|
|
||||||
file.write(output)
|
|
||||||
else:
|
|
||||||
file.write(line)
|
|
||||||
|
|
||||||
def erase_until_newline_after_name(filename,name):
|
|
||||||
with open(filename, 'r') as file:
|
|
||||||
lines = file.readlines()
|
|
||||||
|
|
||||||
with open(filename, 'w') as file:
|
|
||||||
erase = False
|
|
||||||
for line in lines:
|
|
||||||
if "#+name" in line and name in line:
|
|
||||||
erase = True
|
|
||||||
file.write(line)
|
|
||||||
if erase:
|
|
||||||
if line == '\n':
|
|
||||||
erase = False
|
|
||||||
file.write(line)
|
|
||||||
else:
|
|
||||||
file.write(line)
|
|
||||||
|
|
||||||
def read_file(file_path):
|
|
||||||
try:
|
|
||||||
with open(file_path, 'r') as file:
|
|
||||||
file_contents = file.read()
|
|
||||||
return file_contents
|
|
||||||
except FileNotFoundError:
|
|
||||||
return "Not found"
|
|
||||||
|
|
||||||
write_output_to_org_file( "index.org", "blog-table-latest-10.txt", read_file('blog-table-latest-10.txt'))
|
|
||||||
|
|
||||||
|
print("Blog table generated successfully")
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
** The Links table
|
** The Links table
|
||||||
|
:PROPERTIES:
|
||||||
|
:HEADER-ARGS: python :tangle scripts/heading-link-generator.py :comments both
|
||||||
|
:END:
|
||||||
|
|
||||||
#+name: link-list
|
#+name: link-list
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
| [[file:index.org][Home]] | [[file:blogs/blog-index.org][Blogs]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|------+-------+-------+-----+------+-----+-------|
|
||||||
|
|
||||||
# Git | Archive | Series | Art | Links | Support |
|
|
||||||
|
|
||||||
|
|
||||||
*** Write link-list to [[file:link-list.txt]]
|
|
||||||
|
|
||||||
#+begin_src python :results silent
|
*** Read the above link-list
|
||||||
|
|
||||||
|
#+begin_src python
|
||||||
def read_until_newline_after_name(filename,name):
|
def read_until_newline_after_name(filename,name):
|
||||||
with open(filename, 'r') as file:
|
with open(filename, 'r') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
|
@ -607,11 +457,11 @@ def write_to_file(file_path, content):
|
||||||
with open(file_path, 'w') as file:
|
with open(file_path, 'w') as file:
|
||||||
file.write(content)
|
file.write(content)
|
||||||
|
|
||||||
write_to_file('link-list.txt',read_until_newline_after_name('main.org','link-list'))
|
heading_link_list = read_until_newline_after_name('main.org','link-list')
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Read and write the link table in all files in the root directory except [[file:main.org]]
|
*** Write the link table in all files in the root directory except [[file:main.org]]
|
||||||
#+begin_src python :results silent
|
#+begin_src python
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def write_output_to_org_file(file_path, name, output):
|
def write_output_to_org_file(file_path, name, output):
|
||||||
|
@ -652,16 +502,22 @@ def read_file(file_path):
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return "Not found"
|
return "Not found"
|
||||||
|
|
||||||
directory = './'
|
directory = './content/'
|
||||||
for filename in os.listdir(directory):
|
for filename in os.listdir(directory):
|
||||||
if filename.endswith('.org') and filename != 'main.org':
|
if filename.endswith('.org') and filename != 'main.org':
|
||||||
file_path = os.path.join(directory, filename)
|
file_path = os.path.join(directory, filename)
|
||||||
# Process the org file here
|
# Process the org file here
|
||||||
write_output_to_org_file( file_path,"link-list.txt", read_file('link-list.txt'))
|
write_output_to_org_file(file_path,"link-list", heading_link_list)
|
||||||
|
print(f' Heading links added to {file_path}')
|
||||||
|
|
||||||
|
print('All heading links added')
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
** Onion and I2P addresses
|
** Onion and I2P addresses
|
||||||
|
:PROPERTIES:
|
||||||
|
:HEADER-ARGS: python :tangle scripts/generate_and_update_address_files.py :comments both
|
||||||
|
:END:
|
||||||
|
|
||||||
#+name: i2p-b32-address
|
#+name: i2p-b32-address
|
||||||
http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p
|
http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p
|
||||||
|
|
||||||
|
@ -671,7 +527,7 @@ http://acfc2abqv65bdiwimrx74vrlxy6eel66cjlmgqqvdekcrx7ufl3c2cad.onion
|
||||||
|
|
||||||
|
|
||||||
*** Write to txt files
|
*** Write to txt files
|
||||||
#+begin_src python :results silent
|
#+begin_src python
|
||||||
def read_until_newline_after_name(filename,name):
|
def read_until_newline_after_name(filename,name):
|
||||||
with open(filename, 'r') as file:
|
with open(filename, 'r') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
|
@ -694,8 +550,10 @@ def write_to_file(file_path, content):
|
||||||
with open(file_path, 'w') as file:
|
with open(file_path, 'w') as file:
|
||||||
file.write(content)
|
file.write(content)
|
||||||
|
|
||||||
write_to_file('i2p-b32-address.txt',read_until_newline_after_name('main.org','i2p-b32-address'))
|
write_to_file('content/static/i2p-b32-address.txt',read_until_newline_after_name('main.org','i2p-b32-address'))
|
||||||
write_to_file('tor-onionv3-address.txt',read_until_newline_after_name('main.org','tor-onionv3-address'))
|
print('content/static/i2p-b32-address.txt written')
|
||||||
|
write_to_file('content/static/tor-onionv3-address.txt',read_until_newline_after_name('main.org','tor-onionv3-address'))
|
||||||
|
print('content/static/tor-onionv3-address.txt written')
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Read and write addresses to all files
|
*** Read and write addresses to all files
|
||||||
|
@ -740,7 +598,7 @@ def read_file(file_path):
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return "Not found"
|
return "Not found"
|
||||||
|
|
||||||
directory = './'
|
directory = './content/'
|
||||||
for root,dir,filename in os.walk(directory):
|
for root,dir,filename in os.walk(directory):
|
||||||
for file in filename:
|
for file in filename:
|
||||||
if file.endswith('.org') and file != 'main.org':
|
if file.endswith('.org') and file != 'main.org':
|
||||||
|
@ -748,9 +606,11 @@ for root,dir,filename in os.walk(directory):
|
||||||
# Process the org file here
|
# Process the org file here
|
||||||
write_output_to_org_file( file_path,"i2p-b32-address.txt", read_file('i2p-b32-address.txt'))
|
write_output_to_org_file( file_path,"i2p-b32-address.txt", read_file('i2p-b32-address.txt'))
|
||||||
write_output_to_org_file( file_path,"tor-onionv3-address.txt", read_file('tor-onionv3-address.txt'))
|
write_output_to_org_file( file_path,"tor-onionv3-address.txt", read_file('tor-onionv3-address.txt'))
|
||||||
|
print(f' Addresses written in {file_path}')
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
* Things to do
|
* TODO Things to do
|
||||||
** DONE Setup Gitea to host the source code (org files) of the website
|
** TODO Improve css
|
||||||
|
** Put something in [[file:content/index.org]]
|
||||||
|
|
39
news.org
39
news.org
|
@ -1,39 +0,0 @@
|
||||||
#+title: News
|
|
||||||
#+created: [2024-03-01 Fri]
|
|
||||||
#+last_modified: [2024-03-06 Wed]
|
|
||||||
#+setupfile: main.setup
|
|
||||||
|
|
||||||
#+begin_center
|
|
||||||
: +--------------------------------------+
|
|
||||||
: | _ _ |
|
|
||||||
: | | \ | | ___ __ __ ___ |
|
|
||||||
: | | \| | / _ \ \ \ /\ / / / __| |
|
|
||||||
: | | |\ | | __/ \ V V / \__ \ |
|
|
||||||
: | |_| \_| \___| \_/\_/ |___/ |
|
|
||||||
: +--------------------------------------+
|
|
||||||
#+end_center
|
|
||||||
|
|
||||||
#+name: link-list.txt
|
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|
||||||
| [[file:index.org][Home]] | [[file:blogs/blog-list.org][Blog]] | [[file:about.org][About]] | [[file:FAQ.org][FAQ]] | [[file:news.org][News]] | [[file:contact.org][PGP]] | [[file:links.org][Links]] |
|
|
||||||
|------+------+-------+-----+------+-----+-------|
|
|
||||||
|
|
||||||
* TOR and I2P - [2024-03-06 Wed]
|
|
||||||
Went live on I2P
|
|
||||||
#+name: i2p-b32-address.txt
|
|
||||||
http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p
|
|
||||||
|
|
||||||
|
|
||||||
Went live on TOR
|
|
||||||
#+name: tor-onionv3-address.txt
|
|
||||||
http://acfc2abqv65bdiwimrx74vrlxy6eel66cjlmgqqvdekcrx7ufl3c2cad.onion
|
|
||||||
|
|
||||||
|
|
||||||
* First Light - [2024-03-02 Sat]
|
|
||||||
Website went live
|
|
||||||
|
|
||||||
Got our first SSL Certificates
|
|
||||||
|
|
||||||
|
|
||||||
* Big Bang !! - [2024-03-01 Fri]
|
|
||||||
The site was created from scratch.
|
|
3
publish.sh
Normal file
3
publish.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
rsync -avh --delete public/cosmicpirates.space-html/ /var/www/cosmicpirates.space/cosmicpirates.space-html
|
132
scripts/blog-table-generator.py
Normal file
132
scripts/blog-table-generator.py
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
# Generate Main blog list for [[file:content/blogs/blog-index.org]]
|
||||||
|
# The following code block looks at all org files(except [[file:content/blogs/blog-index.org]] ) in the [[file:content/blogs/]] directory and finds there title, creation date, and last modified date and then creates an org table, then this table is stored as a string in the blog_table variable
|
||||||
|
# # begin_src python :results output raw :exports results
|
||||||
|
# #+name: blog-table-generator
|
||||||
|
|
||||||
|
# [[file:../main.org::blog-table-generator][blog-table-generator]]
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# path of the blog directory
|
||||||
|
blogs_directory = "./content/blogs"
|
||||||
|
|
||||||
|
|
||||||
|
# get a list of all things in blogs_directory
|
||||||
|
blog_list = os.listdir(blogs_directory)
|
||||||
|
max_lines_to_scan = 10
|
||||||
|
|
||||||
|
#Only include files which are .org and do no include the main Blog-list.org file which serves as an index
|
||||||
|
b = []
|
||||||
|
for i in range(0,len(blog_list)):
|
||||||
|
if blog_list[i].endswith(".org") and blog_list[i] != 'blog-index.org':
|
||||||
|
b.append(blog_list[i])
|
||||||
|
blog_list=b
|
||||||
|
|
||||||
|
#Sort blog files by last modified time
|
||||||
|
# blog_list.sort(key=lambda x: os.path.getmtime(blogs_directory+x),reverse=True)
|
||||||
|
|
||||||
|
# variable to store output table
|
||||||
|
blog_table = ""
|
||||||
|
|
||||||
|
#prints the heading of the list.
|
||||||
|
blog_table += ("|-\n")
|
||||||
|
blog_table += ("|Title|Last Modified|Created|\n")
|
||||||
|
|
||||||
|
titles = []
|
||||||
|
title_found = False
|
||||||
|
creation_dates = []
|
||||||
|
creation_found = False
|
||||||
|
last_modified_found = False
|
||||||
|
last_modified_dates = []
|
||||||
|
|
||||||
|
# finds the title, last modified time and creation time
|
||||||
|
for blog_no in range(0,len(blog_list)):
|
||||||
|
with open(blogs_directory +'/'+ blog_list[blog_no], "r") as file:
|
||||||
|
creation_found = False
|
||||||
|
last_modified_found = False
|
||||||
|
title_found = False
|
||||||
|
for line_no in range(max_lines_to_scan):
|
||||||
|
try:
|
||||||
|
line = str(next(file))
|
||||||
|
except Exception as e:
|
||||||
|
break
|
||||||
|
if (line.lower()).startswith('#+title') and title_found == False:
|
||||||
|
titles.append((line.split(':',1)[1]).strip())
|
||||||
|
title_found = True
|
||||||
|
elif (line.lower()).startswith('#+created') and creation_found == False:
|
||||||
|
creation_dates.append((line.split(':',1)[1]).strip())
|
||||||
|
creation_found = True
|
||||||
|
elif (line.lower()).startswith('#+last_modified') and last_modified_found == False:
|
||||||
|
last_modified_dates.append((line.split(':',1)[1]).strip())
|
||||||
|
last_modified_found = True
|
||||||
|
if title_found == True and last_modified_found == True and creation_found == True:
|
||||||
|
break
|
||||||
|
if last_modified_found == False:
|
||||||
|
last_modified_dates.append('unknown')
|
||||||
|
if creation_found == False:
|
||||||
|
creation_dates.append('unknown')
|
||||||
|
if title_found == False:
|
||||||
|
titles.append('unknown')
|
||||||
|
blog_table += ("|-\n")
|
||||||
|
|
||||||
|
def sort_multiple_lists(*args):
|
||||||
|
"""This function sorts multiple lists according to the sorting of the first list and returns the sorted lists as a tuple"""
|
||||||
|
|
||||||
|
#Extract the firstlist from the argumnts and find its length
|
||||||
|
first_list = args[0]
|
||||||
|
list_length = len(first_list)
|
||||||
|
|
||||||
|
# Group all corresponding elements into a list of tuples
|
||||||
|
tuples_list = list(zip(*args))
|
||||||
|
|
||||||
|
# Sort the tuples according to there first elements
|
||||||
|
sorted_tuples_list = sorted(tuples_list,key = lambda x: first_list.index(x[0]),reverse = False)
|
||||||
|
|
||||||
|
# Extract the sorted lists and return them
|
||||||
|
return(list(zip(*sorted_tuples_list)))
|
||||||
|
|
||||||
|
|
||||||
|
# Sort all lists according to creation_date
|
||||||
|
sorted_creation_dates,sorted_titles,sorted_last_modified_dates,sorted_blog_list = sort_multiple_lists(creation_dates,titles,last_modified_dates,blog_list)
|
||||||
|
|
||||||
|
for blog_no in range(0,len(blog_list)):
|
||||||
|
blog_table += ("|"+ '[[file:'+ sorted_blog_list[blog_no]+ ']' + '['+sorted_titles[blog_no] + ']]'+ '|' +sorted_last_modified_dates[blog_no] + '|' + sorted_creation_dates[blog_no] + '|\n')
|
||||||
|
# blog-table-generator ends here
|
||||||
|
|
||||||
|
# Write the blog table into [[file:content/blogs/blog-index.org]]
|
||||||
|
|
||||||
|
# [[file:../main.org::*Write the blog table into \[\[file:content/blogs/blog-index.org\]\]][Write the blog table into [[file:content/blogs/blog-index.org]]:1]]
|
||||||
|
def write_output_to_org_file(file_path, name, output):
|
||||||
|
erase_until_newline_after_name(file_path)
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
data = file.readlines()
|
||||||
|
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
for line in data:
|
||||||
|
if '#+name: ' in line and name in line:
|
||||||
|
file.write(line)
|
||||||
|
file.write(output)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
def erase_until_newline_after_name(filename):
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
erase = False
|
||||||
|
for line in lines:
|
||||||
|
if "#+name" in line:
|
||||||
|
erase = True
|
||||||
|
file.write(line)
|
||||||
|
if erase:
|
||||||
|
if line == '\n':
|
||||||
|
erase = False
|
||||||
|
file.write(line)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
write_output_to_org_file( "content/blogs/blog-index.org", "blog-table-complete", blog_table)
|
||||||
|
|
||||||
|
print("Blog table generated successfully")
|
||||||
|
# Write the blog table into [[file:content/blogs/blog-index.org]]:1 ends here
|
84
scripts/generate_and_update_address_files.py
Normal file
84
scripts/generate_and_update_address_files.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
# Write to txt files
|
||||||
|
|
||||||
|
# [[file:../main.org::*Write to txt files][Write to txt files:1]]
|
||||||
|
def read_until_newline_after_name(filename,name):
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
content = ""
|
||||||
|
in_name = False
|
||||||
|
for line in lines:
|
||||||
|
if "#+name" in line and name in line:
|
||||||
|
in_name = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if in_name:
|
||||||
|
if line == '\n':
|
||||||
|
in_name = False
|
||||||
|
else:
|
||||||
|
content += line
|
||||||
|
|
||||||
|
return(content)
|
||||||
|
|
||||||
|
def write_to_file(file_path, content):
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
write_to_file('content/static/i2p-b32-address.txt',read_until_newline_after_name('main.org','i2p-b32-address'))
|
||||||
|
print('content/static/i2p-b32-address.txt written')
|
||||||
|
write_to_file('content/static/tor-onionv3-address.txt',read_until_newline_after_name('main.org','tor-onionv3-address'))
|
||||||
|
print('content/static/tor-onionv3-address.txt written')
|
||||||
|
# Write to txt files:1 ends here
|
||||||
|
|
||||||
|
# Read and write addresses to all files
|
||||||
|
|
||||||
|
# [[file:../main.org::*Read and write addresses to all files][Read and write addresses to all files:1]]
|
||||||
|
import os
|
||||||
|
|
||||||
|
def write_output_to_org_file(file_path, name, output):
|
||||||
|
erase_until_newline_after_name(file_path,name)
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
data = file.readlines()
|
||||||
|
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
for line in data:
|
||||||
|
if '#+name: ' in line and name in line:
|
||||||
|
file.write(line)
|
||||||
|
file.write(output)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
def erase_until_newline_after_name(filename,name):
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
erase = False
|
||||||
|
for line in lines:
|
||||||
|
if "#+name" in line and name in line:
|
||||||
|
erase = True
|
||||||
|
file.write(line)
|
||||||
|
if erase:
|
||||||
|
if line == '\n':
|
||||||
|
erase = False
|
||||||
|
file.write(line)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
def read_file(file_path):
|
||||||
|
try:
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
file_contents = file.read()
|
||||||
|
return file_contents
|
||||||
|
except FileNotFoundError:
|
||||||
|
return "Not found"
|
||||||
|
|
||||||
|
directory = './content/'
|
||||||
|
for root,dir,filename in os.walk(directory):
|
||||||
|
for file in filename:
|
||||||
|
if file.endswith('.org') and file != 'main.org':
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
# Process the org file here
|
||||||
|
write_output_to_org_file( file_path,"i2p-b32-address.txt", read_file('i2p-b32-address.txt'))
|
||||||
|
write_output_to_org_file( file_path,"tor-onionv3-address.txt", read_file('tor-onionv3-address.txt'))
|
||||||
|
print(f' Addresses written in {file_path}')
|
||||||
|
# Read and write addresses to all files:1 ends here
|
82
scripts/heading-link-generator.py
Normal file
82
scripts/heading-link-generator.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
# Read the above link-list
|
||||||
|
|
||||||
|
|
||||||
|
# [[file:../main.org::*Read the above link-list][Read the above link-list:1]]
|
||||||
|
def read_until_newline_after_name(filename,name):
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
content = ""
|
||||||
|
in_name = False
|
||||||
|
for line in lines:
|
||||||
|
if "#+name" in line and name in line:
|
||||||
|
in_name = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if in_name:
|
||||||
|
if line == '\n':
|
||||||
|
in_name = False
|
||||||
|
else:
|
||||||
|
content += line
|
||||||
|
|
||||||
|
return(content)
|
||||||
|
|
||||||
|
def write_to_file(file_path, content):
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
heading_link_list = read_until_newline_after_name('main.org','link-list')
|
||||||
|
# Read the above link-list:1 ends here
|
||||||
|
|
||||||
|
# Write the link table in all files in the root directory except [[file:main.org]]
|
||||||
|
|
||||||
|
# [[file:../main.org::*Write the link table in all files in the root directory except \[\[file:main.org\]\]][Write the link table in all files in the root directory except [[file:main.org]]:1]]
|
||||||
|
import os
|
||||||
|
|
||||||
|
def write_output_to_org_file(file_path, name, output):
|
||||||
|
erase_until_newline_after_name(file_path,name)
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
data = file.readlines()
|
||||||
|
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
for line in data:
|
||||||
|
if '#+name: ' in line and name in line:
|
||||||
|
file.write(line)
|
||||||
|
file.write(output)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
def erase_until_newline_after_name(filename,name):
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
erase = False
|
||||||
|
for line in lines:
|
||||||
|
if "#+name" in line and name in line:
|
||||||
|
erase = True
|
||||||
|
file.write(line)
|
||||||
|
if erase:
|
||||||
|
if line == '\n':
|
||||||
|
erase = False
|
||||||
|
file.write(line)
|
||||||
|
else:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
def read_file(file_path):
|
||||||
|
try:
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
file_contents = file.read()
|
||||||
|
return file_contents
|
||||||
|
except FileNotFoundError:
|
||||||
|
return "Not found"
|
||||||
|
|
||||||
|
directory = './content/'
|
||||||
|
for filename in os.listdir(directory):
|
||||||
|
if filename.endswith('.org') and filename != 'main.org':
|
||||||
|
file_path = os.path.join(directory, filename)
|
||||||
|
# Process the org file here
|
||||||
|
write_output_to_org_file(file_path,"link-list", heading_link_list)
|
||||||
|
print(f' Heading links added to {file_path}')
|
||||||
|
|
||||||
|
print('All heading links added')
|
||||||
|
# Write the link table in all files in the root directory except [[file:main.org]]:1 ends here
|
Loading…
Add table
Reference in a new issue