diff --git a/.gitignore b/.gitignore index bfbb5d1..c501d61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/cosmicpirates.space-gmi/ -/cosmicpirates.space-html/ +/public/ +/.packages/ diff --git a/blog-table-latest-10.txt b/blog-table-latest-10.txt deleted file mode 100644 index bd80909..0000000 --- a/blog-table-latest-10.txt +++ /dev/null @@ -1,4 +0,0 @@ -|- -|Title|Last Modified|Created| -|- -|[[file:./blogs/test_blog_3.org][Test Blog]]||[2024-02-05 Thu]| diff --git a/FAQ.org b/content/FAQ.org similarity index 79% rename from FAQ.org rename to content/FAQ.org index a682175..9be0f2d 100644 --- a/FAQ.org +++ b/content/FAQ.org @@ -17,8 +17,8 @@ : +-------------------------------------------+ #+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]] | -|------+------+-------+-----+------+-----+-------| +#+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]] | +|------+-------+-------+-----+------+-----+-------| diff --git a/about.org b/content/about.org similarity index 64% rename from about.org rename to content/about.org index fdaa1b2..aad558c 100644 --- a/about.org +++ b/content/about.org @@ -13,10 +13,10 @@ : +--------------------------------------+ #+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]] | -|------+------+-------+-----+------+-----+-------| +#+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]] | +|------+-------+-------+-----+------+-----+-------| We think that knowledge should be open to everyone and freely accessible. diff --git a/blogs/blog-list.org b/content/blogs/blog-index.org similarity index 96% rename from blogs/blog-list.org rename to content/blogs/blog-index.org index 2aaef7c..887e082 100644 --- a/blogs/blog-list.org +++ b/content/blogs/blog-index.org @@ -21,7 +21,7 @@ * A list of All Blogs -#+name: blog-table-complete.txt +#+name: blog-table-complete |- |Title|Last Modified|Created| |- diff --git a/blogs/blog-table-complete.txt b/content/blogs/blog-table-complete.txt similarity index 100% rename from blogs/blog-table-complete.txt rename to content/blogs/blog-table-complete.txt diff --git a/blogs/blog.setup b/content/blogs/blog.setup similarity index 100% rename from blogs/blog.setup rename to content/blogs/blog.setup diff --git a/blogs/test_blog_3.org b/content/blogs/test_blog_3.org similarity index 100% rename from blogs/test_blog_3.org rename to content/blogs/test_blog_3.org diff --git a/contact.org b/content/contact.org similarity index 96% rename from contact.org rename to content/contact.org index 00b321f..8f63e96 100644 --- a/contact.org +++ b/content/contact.org @@ -11,10 +11,10 @@ #+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]] | -|------+------+-------+-----+------+-----+-------| +#+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]] | +|------+-------+-------+-----+------+-----+-------| * Dibyashanu Pati diff --git a/index.org b/content/index.org similarity index 80% rename from index.org rename to content/index.org index 1bd7426..45bd886 100644 --- a/index.org +++ b/content/index.org @@ -13,16 +13,9 @@ : +------------------------------------------------------------------------------------------------------------------------+ #+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]] | -|------+------+-------+-----+------+-----+-------| +#+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]] | +|------+-------+-------+-----+------+-----+-------| -* 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]| diff --git a/links.org b/content/links.org similarity index 64% rename from links.org rename to content/links.org index 104fb4e..941bbbd 100644 --- a/links.org +++ b/content/links.org @@ -28,10 +28,10 @@ : +------------------------------------------+ #+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]] | -|------+------+-------+-----+------+-----+-------| +#+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]] | +|------+-------+-------+-----+------+-----+-------| #+TOC: headlines 1 @@ -42,9 +42,4 @@ https://cosmicpirates.space/ ** TOR #+name: tor-onionv3-address.txt -http://acfc2abqv65bdiwimrx74vrlxy6eel66cjlmgqqvdekcrx7ufl3c2cad.onion - - -** I2P -#+name: i2p-b32-address.txt -http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p +Not found \ No newline at end of file diff --git a/main.setup b/content/main.setup similarity index 100% rename from main.setup rename to content/main.setup diff --git a/content/news.org b/content/news.org new file mode 100644 index 0000000..a431985 --- /dev/null +++ b/content/news.org @@ -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 \ No newline at end of file diff --git a/i2p-b32-address.txt b/content/static/i2p-b32-address.txt similarity index 100% rename from i2p-b32-address.txt rename to content/static/i2p-b32-address.txt diff --git a/tor-onionv3-address.txt b/content/static/tor-onionv3-address.txt similarity index 100% rename from tor-onionv3-address.txt rename to content/static/tor-onionv3-address.txt diff --git a/create-site.el b/create-site.el new file mode 100644 index 0000000..e517a4c --- /dev/null +++ b/create-site.el @@ -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!") diff --git a/create.sh b/create.sh new file mode 100755 index 0000000..89604a1 --- /dev/null +++ b/create.sh @@ -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 diff --git a/link-list.txt b/link-list.txt deleted file mode 100644 index d627749..0000000 --- a/link-list.txt +++ /dev/null @@ -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]] | -|------+------+-------+-----+------+-----+-------| diff --git a/main.org b/main.org index 9316492..2339ba8 100644 --- a/main.org +++ b/main.org @@ -3,18 +3,13 @@ * Usage Instructions and Best Practices ** Basic Plan -+ The entire organization of the website is generated by the scripts in this file. -+ These scripts generated org files which are later published in other formats ++ The entire organization of the website is generated by the +scripts in this file+ scripts in the [[file:scripts/]] directory. ++ 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://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 + 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 @@ -258,10 +253,9 @@ o888bood8P' o888o `Y8bod8P' `8oooooo. 8""888P' None #+end_example - ** File Read Write functions *** 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): with open(file_path, 'r') as file: data = file.readlines() @@ -275,9 +269,6 @@ def write_output_to_org_file(file_path, name, output): file.write(line) #+end_src -#+RESULTS: -: None - *** Read txt files #+begin_src python def read_file(file_path): @@ -294,22 +285,21 @@ def read_file(file_path): * Administrative-scripts -:PROPERTIES: -:EXPORT_EXCLUDE_TAGS: noexport -:END: ** Blogs *** Main Blog list -**** Generate Main blog list for [[file:blogs/blog-list.org]] -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]]. -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]]. +:PROPERTIES: +:HEADER-ARGS: python :tangle scripts/blog-table-generator.py :comments both +: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 #+name: blog-table-generator -#+begin_src python :results output raw :exports none +#+begin_src python import os from datetime import datetime # path of the blog directory -blogs_directory = "./blogs/" +blogs_directory = "./content/blogs" # 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 b = [] 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]) 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. -print("|-") -print("|Title|Last Modified|Created|") +blog_table += ("|-\n") +blog_table += ("|Title|Last Modified|Created|\n") titles = [] title_found = False @@ -336,6 +329,7 @@ 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: @@ -364,7 +358,7 @@ for blog_no in range(0,len(blog_list)): creation_dates.append('unknown') if title_found == False: titles.append('unknown') -print("|-") +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""" @@ -382,39 +376,15 @@ def sort_multiple_lists(*args): # Extract the sorted lists and return them return(list(zip(*sorted_tuples_list))) -# print((creation_dates,last_modified_dates,blog_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) -# 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)): - 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 - -#+RESULTS: blog-table-generator -|- -|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 +**** Write the blog table into [[file:content/blogs/blog-index.org]] +#+begin_src python def write_output_to_org_file(file_path, name, output): erase_until_newline_after_name(file_path) with open(file_path, 'r') as file: @@ -445,146 +415,26 @@ def erase_until_newline_after_name(filename): 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( "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')) +write_output_to_org_file( "content/blogs/blog-index.org", "blog-table-complete", blog_table) +print("Blog table generated successfully") #+end_src ** The Links table +:PROPERTIES: +:HEADER-ARGS: python :tangle scripts/heading-link-generator.py :comments both +:END: #+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]] | -|------+------+-------+-----+------+-----+-------| - -# Git | Archive | Series | Art | Links | Support | +|------+-------+-------+-----+------+-----+-------| +| [[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]] | +|------+-------+-------+-----+------+-----+-------| -*** 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): with open(filename, 'r') as file: lines = file.readlines() @@ -607,11 +457,11 @@ def write_to_file(file_path, content): with open(file_path, 'w') as file: 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 -*** Read and write the link table in all files in the root directory except [[file:main.org]] -#+begin_src python :results silent +*** Write the link table in all files in the root directory except [[file:main.org]] +#+begin_src python import os def write_output_to_org_file(file_path, name, output): @@ -652,16 +502,22 @@ def read_file(file_path): except FileNotFoundError: return "Not found" -directory = './' +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.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 - ** Onion and I2P addresses +:PROPERTIES: +:HEADER-ARGS: python :tangle scripts/generate_and_update_address_files.py :comments both +:END: + #+name: i2p-b32-address http://dbtjoqs5jnsyq6m6r35a47jix2v4zeloz5fpxi6htwihpnv3fcxq.b32.i2p @@ -671,7 +527,7 @@ http://acfc2abqv65bdiwimrx74vrlxy6eel66cjlmgqqvdekcrx7ufl3c2cad.onion *** Write to txt files -#+begin_src python :results silent +#+begin_src python def read_until_newline_after_name(filename,name): with open(filename, 'r') as file: lines = file.readlines() @@ -694,8 +550,10 @@ def write_to_file(file_path, content): with open(file_path, 'w') as file: file.write(content) -write_to_file('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')) +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') #+end_src *** Read and write addresses to all files @@ -740,7 +598,7 @@ def read_file(file_path): except FileNotFoundError: return "Not found" -directory = './' +directory = './content/' for root,dir,filename in os.walk(directory): for file in filename: 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 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}') #+end_src -* Things to do -** DONE Setup Gitea to host the source code (org files) of the website +* TODO Things to do +** TODO Improve css +** Put something in [[file:content/index.org]] diff --git a/news.org b/news.org deleted file mode 100644 index 488634c..0000000 --- a/news.org +++ /dev/null @@ -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. diff --git a/publish.sh b/publish.sh new file mode 100644 index 0000000..d5a7805 --- /dev/null +++ b/publish.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +rsync -avh --delete public/cosmicpirates.space-html/ /var/www/cosmicpirates.space/cosmicpirates.space-html diff --git a/scripts/blog-table-generator.py b/scripts/blog-table-generator.py new file mode 100644 index 0000000..032d0be --- /dev/null +++ b/scripts/blog-table-generator.py @@ -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 diff --git a/scripts/generate_and_update_address_files.py b/scripts/generate_and_update_address_files.py new file mode 100644 index 0000000..bea6312 --- /dev/null +++ b/scripts/generate_and_update_address_files.py @@ -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 diff --git a/scripts/heading-link-generator.py b/scripts/heading-link-generator.py new file mode 100644 index 0000000..de38cd2 --- /dev/null +++ b/scripts/heading-link-generator.py @@ -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