genorg.pl
author Pranshu Sharma <pranshu@bauherren.ovh>
Wed, 18 Dec 2024 00:58:13 +1000
changeset 13 da3b9ba1a7f0
parent 12 1be91608b33c
child 14 31e45dd2a894
permissions -rwxr-xr-x
more duc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     1
#!/usr/bin/perl
1
0b7be2e78d3b Added more documentation
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 0
diff changeset
     2
# Author: Pranshu Sharma <pranshu@bauherren.ovh>
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     3
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     4
use v5.36.0;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     5
use strict;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     6
use warnings;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     7
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     8
use XML::LibXML;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     9
use File::Find;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    10
use File::Copy qw(copy move);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    11
use Cwd;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    12
use experimental qw(declared_refs);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    13
use Data::Dumper;
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
    14
use POSIX;
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
    15
# !! Add seperatio between title and identifier
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    16
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    17
# Fix up CLI interface
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    18
# Add option ro set cache to 0 through command line
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    19
# Print required elisp code it is in $req_config
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    20
# Add config option for $max_rss and $max_cat
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    21
# Document link to file x from file x no work
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    22
# Variable for map_css
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
    23
# Remove the desc
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    24
# Domain thing as well
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
    25
# 2 articles 1 day better sorting
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
    26
# cataogry linking
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    27
my $cache = 1;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    28
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    29
my $config_file = "genorg-conf";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    30
my $dir = "blog";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    31
my $outdir = "out/";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    32
my $emacs = "emacs";
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    33
my $art_css = "astyle.css";
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    34
my $cat_css ="cstyle.css";
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    35
my $no_name_dir = "c";
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
    36
my $cache_file = "genorg-cache/cache.xml";
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    37
my $domain = "p.bauherren.ovh";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    38
my $max_rss = 30;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    39
# The first page has one less article.  Think of it as a feature.
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    40
my $max_cat = 10;
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    41
my $blog_title = "Pranshu's blog";
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    42
my ($home, $about) = ("home.html", "about.html");
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    43
my $etc_files;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    44
my $nav_id = "nav";
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    45
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    46
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid ($<);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    47
my $template = <<"END";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    48
#+title: Test document
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    49
#+subtitle: This is the subtitle
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    50
#+author: $username
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    51
#+keywords: tag thing | related
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    52
#+options: html-link-use-abs-url:nil html-postamble:auto
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    53
#+options: html-preamble:t html-scripts:nil html-style:t
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    54
#+options: html5-fancy:nil tex:t
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    55
#+options: tex:mathjax
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    56
#+html_doctype: html5
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    57
#+html_container: div
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    58
#+html_content_class: content
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    59
#+html_link_home:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    60
#+html_link_up:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    61
#+html_mathjax:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    62
#+html_equation_reference_format: \eqref{%s}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    63
#+html_head:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    64
#+html_head_extra:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    65
#+infojs_opt:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    66
#+creator: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 31.0.50 (<a href="https://orgmode.org">Org</a> mode 9.7.11)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    67
#+latex_header:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    68
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    69
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    70
my $req_config = <<"END";
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    71
(require 'org)
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    72
(require 'ob)
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    73
(org-link-set-parameters "genorg"
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    74
			 :follow nil
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    75
			 :export
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    76
			 #'(lambda (link desc _ _)
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    77
			     (format "<a class=\"rakim\" href=\"%s\">%s</a>" desc link))
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    78
			 :store nil)
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    79
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    80
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
    81
my $custom_code = "(list 1)";
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
    82
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    83
my $navbar = <<"END" =~ s/\n\s+//gr;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    84
<ul>
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    85
  <li> <a href="LINK">Home</a> </li>
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    86
  <li> <a href="LINK">Catagories</a> </li>
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
    87
  <li> <a href="LINK">About</a>  </li>
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    88
</ul>
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    89
END
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
    90
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    91
my $elisp_code = <<"END" =~ s/\n\s+//gr;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    92
(let ((ls '(LIST)))
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    93
  (require 'org)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    94
  (mapc
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    95
   (lambda (b)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    96
     (with-current-buffer b
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    97
       (when (and (not (string-match "^ " (buffer-name b)))
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    98
		  (eq major-mode 'org-mode))
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    99
	 (org-export-to-file 'html (pop ls)))))
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   100
   (buffer-list))
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   101
   (kill-emacs))
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   102
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   103
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   104
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   105
my ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   106
  = split /SPLIT/ ,<<"END" =~ s/\n\s+//gr;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   107
<!DOCTYPE html>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   108
<html lang="en">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   109
  <head>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   110
    <meta charset="UTF-8">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   111
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   112
    <title>TITLE</title>
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   113
    <link rel="stylesheet" href="CSS">
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   114
  </head>
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   115
  <body>
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   116
    NAV
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   117
    <h1> BTIT </h1>
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   118
SPLIT
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   119
    <ul id="cataogries">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   120
SPLIT 
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   121
      <li> <a href="LINK">  CATAG (NUMBER)</a>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   122
SPLIT
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   123
    </ul>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   124
    <div>
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   125
      <h2> All articles <a id="rss" href="rss.xml">(rss)</span> </h2> <hr>
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   126
SPLIT
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   127
   <a href="LINK">
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   128
     <strong> TITLE </strong> <span>DATE</span> <i>CATAG</i>
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   129
     <hr>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   130
  </a>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   131
SPLIT
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   132
   <a href="LINK">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   133
     <strong> TITLE </strong> <span>DATE</span>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   134
     <hr>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   135
   </a>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   136
SPLIT
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   137
    </div>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   138
  </body>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   139
</html>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   140
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   141
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   142
my $help = <<"END";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   143
genorg [option] [dir|file]
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   144
Option can be:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   145
 -t FILE : Make a template org file at FILE
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   146
 -h      : Help
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   147
 -c FILE : sepcify a new config file instead of genorg-conf
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   148
 -r      : unconditionally remake org files
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   149
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   150
If no option is set, accept a directory to generate.
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   151
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   152
$config_file follow the syntax of:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   153
VAR VALUE
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   154
where VAR can be:
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   155
 emacs-path : The value should be path of emacs. 'emacs' by default.
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   156
 css        : The path of the css file to use.
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   157
 in_dir     : The directory that contains the files.
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   158
 out_dir    : the output directory.
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   159
 no_name_dir: The directory for generate files.  This means in_dir/no_name_dir
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   160
              cannot exist.
12
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   161
 etc_files  : Space sperated list of files to be navved up
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   162
 cache      : xml cache file
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   163
 home       : home file
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   164
 about      : about file
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   165
 domain     : domain (for rss)
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   166
 title      : title of the blog
13
da3b9ba1a7f0 more duc
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 12
diff changeset
   167
da3b9ba1a7f0 more duc
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 12
diff changeset
   168
As soon as config file comes accross '>>---', the rest of the file
da3b9ba1a7f0 more duc
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 12
diff changeset
   169
is now the elisp code used in emacs startup.
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   170
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   171
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   172
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   173
my $rss_entry = <<"END" =~ s/\n\s+//gr;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   174
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   175
<rss version=\"2.0\">
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   176
 <channel>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   177
  <title>W3Schools Home Page</title>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   178
  <link>https://www.w3schools.com</link>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   179
  <description>Free web building tutorials</description>"
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   180
END
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   181
  
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   182
my %config_vars =
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   183
  (
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   184
   'emacs-path' => \$emacs,
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   185
   css => \$art_css,
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   186
   indir => \$dir,
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   187
   outdir => \$outdir,
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   188
   no_name_dir => \$no_name_dir,
12
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   189
   etc_files => \$etc_files,
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   190
   cache => \$cache_file,
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   191
   home => \$home,
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   192
   about => \$about,
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   193
   domain => \$domain,
1be91608b33c addded way more cusotmisation options and fixed up docu
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 11
diff changeset
   194
   title => \&blog_title
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   195
  );
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   196
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   197
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   198
sub read_config ($path) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   199
  open my $fh, '<', $path or die "Couldn't open config file\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   200
  while (<$fh>) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   201
    next if /^\s+$/;
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   202
    if (/^>>---+/) {
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   203
      local $/;
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   204
      $custom_code = <$fh>;
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   205
      return;
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   206
    }
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   207
    chomp;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   208
    my ($directive, $rest) = split /\s+/, $_, 2;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   209
    if (exists($config_vars{$directive})) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   210
      ${$config_vars{$directive}} = $rest;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   211
    } else {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   212
      print "Unknown variable $directive\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   213
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   214
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   215
  close $fh;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   216
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   217
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   218
sub help_and_bye {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   219
  print $help;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   220
  exit;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   221
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   222
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   223
sub template ($file) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   224
  $file // die "-t needs an argument.\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   225
  $file =~ s/\.org$//;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   226
  open my $fh, '>', $file . ".org" or die $file . " couldn't be opened\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   227
  print $fh $template;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   228
  close $fh;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   229
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   230
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   231
# Reletive file from the perspect of file1, to file2
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   232
sub prel_path ($from, $to) {
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   233
  return $to =~ s/^.//r if $from eq $to;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   234
  my \(@f1, @f2) = map [m{/[^/]+}g], ($from, $to);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   235
  # return substr($f1[$#f1], 1) if $from =~ $to;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   236
  while (@f1 && @f2 && $f1[0] =~ $f2[0]) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   237
    shift @f1;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   238
    shift @f2;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   239
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   240
  my $p = @f1-1;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   241
  local $" = "";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   242
  "../" x ($p > 0 ? $p : 0) . substr("@f2", 1);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   243
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   244
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   245
my @org_exps;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   246
my @files_to_make;
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   247
my @files_to_move;
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   248
my @navify_files;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   249
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   250
sub wanted {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   251
  my $n_path = $outdir . prel_path ($dir,  "$File::Find::name/");
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   252
  # We need to mirror the direcotry structure
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   253
  if (-d) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   254
    push @files_to_make, $n_path || die "Couldn't make directory $n_path\n"
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   255
      unless -d $n_path;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   256
    return;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   257
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   258
  if (/\.org$/) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   259
    push @org_exps, substr $n_path, length($outdir);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   260
  } else {
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   261
    push @files_to_move, $File::Find::name
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   262
  }
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   263
  
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   264
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   265
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   266
my @modified_files;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   267
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   268
# Export @org_exps
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   269
sub conv_files {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   270
  my %changed_files;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   271
  # Remove files that are already converted
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   272
  for my $rel_file (@org_exps) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   273
    # Emacs need the full file path
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   274
    my ($file, $to) = map { getcwd . "/$_" . $rel_file} ($dir, $outdir);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   275
    s/org$/html/ for ($to, $rel_file);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   276
    unless ($cache && -f $to && (stat($to))[9] > (stat($file))[9]) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   277
      $changed_files{$file} = $to;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   278
      push @modified_files, $rel_file;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   279
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   280
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   281
  %changed_files // exit;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   282
  $elisp_code =~ s/LIST/join '', map "\"$_\" ", values %changed_files /e;
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   283
  open my $fh, '-|', ($emacs, '-Q','--eval', "(progn $custom_code)", keys %changed_files, "--eval" , "$elisp_code");
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   284
  close $fh;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   285
  \%changed_files
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   286
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   287
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   288
my $cdir;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   289
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   290
$ARGV[0] // die "No arguments provided\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   291
while ($_ = shift @ARGV) {
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   292
  /^-c$/ && do { print "$req_config\n"; exit };
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   293
  /^(-h|--?help)$/ && help_and_bye;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   294
  /^-t$/ && do { template shift @ARGV ; exit };
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   295
  /^-c$/ && do { $config_file = shift @ARGV; next };
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   296
  /^-d$/ && do { $cache = 0; next };
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   297
  $cdir = $_;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   298
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   299
$cdir || die "directory not provided\n";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   300
main();
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   301
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   302
my %catags;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   303
my @arts;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   304
my $cache_dom;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   305
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   306
sub main {
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   307
    s!/*$!/! for ($outdir, $dir);
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   308
    -d $cdir or help_and_bye;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   309
    mkdir $outdir;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   310
    chdir $cdir or die "Couldn't access $cdir\n";
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   311
    read_config $config_file;
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   312
    my @navify_files = map {"$dir$_"} ($about, $home, $etc_files ? split(/[ \t]+/, $etc_files) : ());
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   313
    -d $dir or die "$dir doesn't exist \n";
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   314
    find (\&wanted, $dir);
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   315
    for my $f (@files_to_move) {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   316
      my $dest = $f =~ s#$dir/?#$outdir#er;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   317
      if (grep(m#^$f$#, @navify_files)) {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   318
	# YAY we have to sub navbar and copy whoop whoop
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   319
	open my $file_tc, '<', $f or die "file no open, grrr!";
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   320
	open my $file_out, '>', $dest;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   321
	local $/;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   322
	print $file_out ((<$file_tc>) =~ s/NAV/nav_up("$dest" =~ s%.+?\/%%r,1)/er);
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   323
	map \&close, ($file_tc, $file_out);
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   324
      } else {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   325
	copy $f, $dest;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   326
      }
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   327
    }
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   328
    mkdir for @files_to_make;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   329
    values %{conv_files()};
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   330
    $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   331
    chdir $outdir;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   332
    @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps;
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   333
    finalise_html();
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   334
    chdir '..';
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   335
    populate_cache();
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   336
}
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   337
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   338
sub populate_cache {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   339
  my $dom = XML::LibXML::Document->new('1.0', 'UTF-8');
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   340
  my $root = $dom->createElement('root');
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   341
  my %c_els;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   342
  for my $art (@arts) {
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   343
    # We need the: related, file, date
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   344
    my ($art_el, $date, $title, $ca, $related, $utitle) =
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   345
      map {$dom->createElement($_)} ("art", "date", "title", "catag", "related", "utitle");
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   346
    $art_el->{path} = $art->{file};
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   347
    $ca->appendText($art->{catag});
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   348
    $title->appendText($art->{title});
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   349
    $date->appendText($art->{date}->text_easy);
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   350
    $utitle->appendText($art->{utitle});
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   351
    my @ll = @{$art->{links}};
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   352
    if (@ll) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   353
      my $links = $dom->createElement('links');
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   354
      for (@ll) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   355
	my $link = $dom->createElement("link");
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   356
	$link->{catag} = $_->[0];
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   357
	$link->appendText($_->[1]);
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   358
	$links->appendChild($link);
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   359
      }
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   360
      $art_el->appendChild($links);
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   361
    }
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   362
    my $rel_str;
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   363
    for my $thing ($art->{related}) {
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   364
      for (@{$thing}) {
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   365
	my ($catag, $artt) = @{$_};
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   366
	my $rel_str .= "\"$catag\"" . ($artt && "->\"$artt\"");
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   367
	$related->appendText("\"$catag\"" . ($artt && "->\"$artt\" "));
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   368
      }
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   369
    }
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   370
    $art_el->appendChild($_) for ($date, $ca, $related, $title, $utitle);
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   371
    $root->appendChild($art_el);
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   372
  }
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   373
  $root->appendChild($_) for values %c_els;
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   374
  $dom->setDocumentElement($root);
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   375
  open my $fh, '>' , $cache_file;
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   376
  print $fh ($dom->toString(1) =~ s/(.+)/$1\n<!-- Nicley formated :() -->/r);
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   377
  close $fh;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   378
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   379
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   380
sub entry {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   381
  my ($data, $catagory) = @_;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   382
  my $str = defined $catagory
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   383
    ? ($h_en_cat =~ s/CATAG/$data->{catag}/er) : $h_en;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   384
  my $prel_path = "/$no_name_dir/" . (defined $catagory ? "c" : "c/b");
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   385
  $str =~ s/DATE/$data->{date}->fmt/er
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   386
    =~ s/TITLE/$data->{utitle}/er
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   387
    =~ s|LINK|prel_path($prel_path, '/'. $data->{file})|er
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   388
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   389
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   390
sub rss_en ($data) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   391
  my $thing = <<"END" =~ s/\n\s+//gr;
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   392
 <item>
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   393
    <title>TITLE</title>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   394
    <link>LINK</link>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   395
    <description>DESC</description>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   396
  </item>
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   397
END
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   398
  $thing 
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   399
    =~ s|LINK|"$domain/" . $data->{file}|er
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   400
      =~ s/TITLE/$data->{utitle}/er;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   401
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   402
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   403
sub min ($x, $y) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   404
  ($x, $y)[$x > $y]
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   405
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   406
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   407
# @_ has to be in format of [STRING, LINK]
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   408
sub list2paginaiton {
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   409
  my $page = shift;
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   410
  '<ul>' . join ("", map {
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   411
    my ($str, $file) = @{$_};
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   412
    $str = "<span class=\"psel\">$str</span>" if $file && ($file == $page);
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   413
    defined $file ?
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   414
      "<li><a href=\"$file.html\">$str</a>" : $str
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   415
    } ((["←", $page - 1]) x!! ($page - 1),
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   416
       @_,
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   417
       (["→", $page + 1]) x ($page != $_[$#_]->[1]))) . '</ul>'
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   418
     }
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   419
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   420
sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path, $title, $rp) {
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   421
  return $fh if $art_num == 0 || $art_num % $max_cat;
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   422
  my $cpage = $art_num / $max_cat;
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   423
  print $fh panigation($cpage, ceil($total_articles / $max_cat), $path);
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   424
  open $fh, '>', $path . '/' . ($cpage + 1).'.html';
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   425
  # ($h_intro . $h_c_intro, $blog_title, "a/c");
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   426
  print $fh cssbs($h_intro, $title, $rp);
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   427
  $fh;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   428
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   429
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   430
sub panigation ($page, $no_pages, $dir) {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   431
  if ($no_pages < 9) {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   432
    list2paginaiton ($page, (map [$_, $_], (1..$no_pages)))
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   433
  } elsif (4 < $page <= ($no_pages - 4)) {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   434
    list2paginaiton
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   435
      ($page,
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   436
       [1, 1],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   437
       ["<li>..."],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   438
       (map [$_, $_], (($page-2)..($page+2))),
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   439
       ["<li>..."],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   440
       [($no_pages) x 2])  
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   441
    } elsif ($page < 6) {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   442
      list2paginaiton $page,
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   443
	((map [$_, $_], (1..5)),
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   444
	 ["<li>..."],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   445
	 [($no_pages) x 2])
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   446
      } else {
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   447
	list2paginaiton $page,
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   448
	  ([1,1],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   449
	   ["<li>..."],
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   450
	   (map [$_, $_], (($no_pages - 5)..$no_pages)))
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   451
	}
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   452
}
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   453
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   454
sub get_art($cat, $id) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   455
  for (@arts) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   456
    return $_ if $_->{catag} eq $cat && $_->{title} eq $id
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   457
  }
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   458
}
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   459
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   460
sub nav_up {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   461
  my ($path) = @_;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   462
  my @links = ($home, 'c/1.html', $about);
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   463
  my $nav = shift ? $navbar : "<div class\"$nav_id\">$navbar</div>";
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   464
  $nav =~ s#LINK#prel_path("/$path", "/". shift @links)#ger;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   465
}
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   466
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   467
sub cssbs($s,$t,$p){
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   468
  $s =~ s|CSS|prel_path("/$p","/$cat_css")|er
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   469
    =~ s/TITLE|BTIT/$t/ger
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   470
    =~ s/NAV/nav_up($p)/er;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   471
}
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   472
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   473
sub modify_art ($file, $dom) {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   474
  # I guess we can rely on navbar not changed, if it did then user
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   475
  # would need to call with -d option
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   476
  return $dom unless grep /^$file$/, @modified_files;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   477
  # We add css, navbar
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   478
  for ($dom->findnodes('/html/body')) {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   479
    # my @cds = $_->childNodes;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   480
    my $nav_el = $dom->createElement('div');
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   481
    $nav_el->{id} = $nav_id;
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   482
    $nav_el->appendWellBalancedChunk(nav_up($file));
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   483
    $_->insertBefore($nav_el, $_->childNodes->[0])
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   484
  }
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   485
  for ($dom->findnodes('/html/head')) {
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   486
    my $link = $dom->createElement('link');
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   487
    $link->{rel} = "stylesheet";
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   488
    $link->{href} = prel_path("/$file", "/$art_css");
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   489
    $_->appendChild($link);
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   490
  }
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   491
  $dom;
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   492
}
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   493
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   494
sub finalise_html {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   495
  mkdir $no_name_dir;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   496
  open my $fh, '>', "$no_name_dir/1.html";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   497
  open my $mrss, '>', "$no_name_dir/rss.xml"; # The master rss file
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   498
  print $mrss $rss_entry;
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   499
  print $fh cssbs($h_intro . $h_c_intro, $blog_title, "a/c");
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   500
  my (%c_files, %r_files);	# Cataogry files and rss
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   501
  
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   502
  for my $cat (sort { $catags{$b} <=> $catags{$a} } keys(%catags)) {
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   503
    my $num = $catags{$cat};
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   504
    # ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   505
    print $fh $h_cat_li =~ s/NUMBER/$num/re
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   506
      =~ s/CATAG/$cat/er
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   507
      =~ s=LINK="$cat/1.html"=er;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   508
    mkdir "$no_name_dir/$cat";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   509
    open $c_files{$cat}, '>', "$no_name_dir/$cat/1.html";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   510
    open $r_files{$cat}, '>', "$no_name_dir/$cat/rss.xml";
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   511
    print {$r_files{$cat}} $rss_entry;
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   512
    print {$c_files{$cat}}
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   513
      cssbs($h_intro, "$cat  <a id=\"rss\" href=\"rss.xml\">(rss)</span> ", "a/b/c");
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   514
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   515
  print $fh $h_chap;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   516
  # :-)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   517
  my $total_articles = () =  map {(1)x$_} values %catags;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   518
  # Now we iterate through the articles and add their index
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   519
  my ($n_fh, $n_mrss, %n_rss) = (0,0);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   520
  my %n_cat;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   521
  for my $art (@arts) {
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   522
    # TODO do we need $title?
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   523
    my ($catag, $title) = @{$art}{qw(catag title)};
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   524
    my $rentry = rss_en $art;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   525
    if (($n_rss{$catag} // 0) < $max_rss) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   526
      print {$r_files{$catag}} $rentry;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   527
      ++$n_rss{$catag};
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   528
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   529
    if ($n_mrss < $max_rss) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   530
      print $mrss $rentry;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   531
      ++$n_mrss
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   532
    }
2
c4ca65113229 Pagination major progress
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 1
diff changeset
   533
    # ($fh, $art_num, $total_articles, $path)
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   534
    $fh = move_on_if_neccasary
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   535
      $fh, $n_fh, $total_articles, $no_name_dir, "All articles", "a/c";
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   536
    $n_fh++;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   537
    print $fh entry $art, 1;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   538
    my $ncat = \$n_cat{$catag};
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   539
    ++$$ncat;
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   540
    my $cfh = \$c_files{$catag};
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   541
    $$cfh = move_on_if_neccasary
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   542
      $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag", $catag, "a/c/b";
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   543
    print {$$cfh} entry $art;
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   544
    my $a_file = $art->{file};
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   545
    if (1 or grep /^$a_file$/, @modified_files) {
9
58b72fea234c IT IS DONE
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 8
diff changeset
   546
      my $doom = modify_art($a_file, linkify($art));
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   547
      open my $h_file, '>', $a_file;
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   548
      print $h_file $doom->toStringHTML;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   549
      close $h_file;
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   550
    }
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   551
  }
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   552
  print $fh panigation ((ceil $n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   553
  print $fh $h_end;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   554
  close $fh;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   555
  for (values %c_files) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   556
    print $_ $h_end;
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   557
    close $_;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   558
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   559
  print $mrss '</channel> </rss>';
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   560
  for (values %r_files) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   561
    print $_ '</channel> </rss>';;
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   562
    close $_;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   563
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   564
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   565
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   566
sub linkify ($art) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   567
  # if $art->{dom} is undefined, we must sadly parse again
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   568
  my @links;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   569
  my @olinks = @{$art->{links} //[]};
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   570
  my $bom = $art->{dom} // XML::LibXML->load_html(location => $art->{file});
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   571
  for ($bom->findnodes('//a[@class="rakim"]')) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   572
    my $key;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   573
    my $link_text;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   574
    if (@olinks) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   575
      $key = pop @olinks;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   576
    } else {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   577
      ($key) = parse_keywords($_->to_literal);
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   578
      $link_text = $_->{href};
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   579
      $_->removeChild($_->firstChild());
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   580
      $_->appendText($link_text);
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   581
    }
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   582
    push @links, $key;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   583
    my $l = get_art(@{$key})->{file} or die "Link not found in $art->{filename}\n";
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   584
    $_->{href} = prel_path("/".$art->{file}, "/$l");
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   585
  }
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   586
  $art->{links} = \@links;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   587
  return $bom
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   588
}
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   589
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   590
# I don't want to prepopulate, as it is not known which ones are
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   591
# usless and outdated, and it would be a waste of cycles parsing
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   592
# something to know it is not needed
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   593
sub getcache ($fn) {
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   594
  $cache_dom || return 0;
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   595
  for my $d ($cache_dom->findnodes("/root/art[\@path=\"$fn\"]")) {
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   596
    # TODO related
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   597
    my %dome = ('file' => $fn);
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   598
    (@dome{'title', 'catag', 'utitle'}, my $date) =
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   599
      map
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   600
      { $d->getChildrenByTagName($_)->[0]->to_literal }
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   601
      qw[title catag  utitle date];
7
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   602
    for ($d->getChildrenByTagName("links")) {
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   603
      my @ll = map [$_->{catag}, $_->to_literal],
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   604
	($_->getChildrenByTagName('link'));
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   605
      $dome{links} = \@ll;
f00ed34eca17 massive
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 6
diff changeset
   606
    }
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   607
    $catags{$dome{catag}}++;
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   608
    $dome{date} = PDate->new(split /-/, $date);
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   609
    return \%dome;
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   610
  }
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   611
  return 0;
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   612
}
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   613
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   614
sub html_fixup ($filename) {
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   615
  if ($cache && !grep /^$filename$/, @modified_files) {
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   616
    for (getcache($filename)) {
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   617
      return $_ if $_
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   618
    }
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   619
  }
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   620
  my $dom =
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   621
    XML::LibXML->load_html(location  => $filename);
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   622
  my %data = ('file', $filename);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   623
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   624
  # We don't need style or table of contents heading (if exists)
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   625
  for my $xpath ('/html/head/style', '/html/body/div/div[@id="table-of-contents"]/h2') {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   626
    $_->parentNode->removeChild($_) for $dom->findnodes($xpath) 
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   627
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   628
  
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   629
  # Info we need
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   630
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   631
  # Date
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   632
  for ($dom->findnodes('/html/body/div[@id="postamble"]/p[@class="date"]')) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   633
    my $text = $_->to_literal;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   634
    if ($text =~ /^Date: (\d+)-(\d+)-(\d+)/) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   635
      my $date = PDate->new($1, $2, $3);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   636
      $data{date} = $date;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   637
      my $p = $_->parentNode;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   638
      $p->parentNode->removeChild($p);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   639
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   640
  }
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   641
  # Title
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   642
  for ($dom->findnodes('/html/head/title')) {
8
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 7
diff changeset
   643
    $data{utitle}  = $_->to_literal;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   644
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   645
  # keywords/catogry
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   646
  for my $node ($dom->findnodes('/html/head/meta')) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   647
    (my $cont = $node->getAttribute('content')) || next;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   648
    for ($node->getAttribute('name')) {
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   649
      if (/keywords/) {
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   650
	my ($key, $rest) = parse_keywords($cont);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   651
	@data{qw[catag title]} = @{$key};
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   652
	$catags{$data{catag}}++;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   653
	$rest =~ s/\s+\|\s+//;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   654
	while ($rest) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   655
	  (my $t,$rest) = parse_keywords($rest);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   656
	  push @{$data{related}}, $t;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   657
	}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   658
      } else {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   659
	next;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   660
      }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   661
      $node->parentNode->removeChild($node);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   662
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   663
  }
3
bf4ae6f1dbbf Half shit cache fixup
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 2
diff changeset
   664
  $data{dom} = $dom;
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   665
  \%data;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   666
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   667
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   668
sub parse_keywords ($str) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   669
  if ($str =~ s/\s*(?:"(.+?)"|(\w+))\s*->(?:\s*(?:"(.+?)"|(\w+)))//) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   670
    ([$1 // $2, $3 // $4], $str);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   671
  } else {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   672
    die "Keywords not arranged properly\n"
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   673
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   674
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   675
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   676
# I wonder if sean combs has made a similar class
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   677
{
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   678
  package PDate;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   679
  
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   680
  sub new {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   681
    my $class = shift;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   682
    my $self = { year => 0 + shift,
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   683
		 month => 0 + shift,
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   684
		 day => 0 + shift,
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   685
	       };
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   686
    bless $self, $class;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   687
    return $self;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   688
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   689
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   690
  # $d1 is greater than $d2
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   691
  sub cmp  {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   692
    my ($d1, $d2) = @_;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   693
    for ($d1->{year} <=> $d2->{year},
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   694
	 $d1->{month} <=> $d2->{month},
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   695
	 $d1->{day} <=> $d2->{day}) {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   696
      return $_ unless $_ == 0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   697
    }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   698
    0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   699
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   700
  use overload '<=>' => \&cmp;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   701
 
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   702
  sub fmt {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   703
    my $self = shift;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   704
    my @months =
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   705
      qw(January Febuary March April May June July August September November October December);
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   706
    my $n = $self->{day};
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   707
    if ($n == 1) { $n = '1st' }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   708
    elsif (($n - 2) % 10 == 0) { $n = "${n}nd" }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   709
    elsif (($n - 3) % 10 == 0) { $n = "${n}rd" }
5
24fc5a406138 Safe spot
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 4
diff changeset
   710
    else { $n = "${n}th" }
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   711
    $months[$self->{month} - 1] . " $n, " . $self->{year}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   712
  }
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   713
    
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   714
  sub short_fmt {
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   715
    my $self = shift;
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   716
    join "-", ($self->{year}, $self->{month}, $self->{day});
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   717
  }
4
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   718
  sub text_easy {
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   719
    my $self = shift;
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   720
    join "-", ($self->{year}, $self->{month}, $self->{day});
c98c7c32ab46 Cache output, found the best soltuion
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 3
diff changeset
   721
  }
0
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   722
}
1f2f88ea2e78 inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   723
6
c576e88fef13 It's starting to feel messy now
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 5
diff changeset
   724