Parcourir la source

WIP towards presentation support and auto-reload

George Baugh il y a 1 mois
Parent
commit
74a1b55cf5

+ 6 - 3
.gitignore

@@ -11,10 +11,13 @@ nytprof*
 www/nytprof
 pm_to_blib
 pod2htmd.tmp
-list.min.json
-highlight.min.js
-obsidian.min.css
+www/scripts/list.min.json
+www/scripts/highlight.min.js
 www/scripts/chart.js
+www/scripts/reveal.js
+www/styles/obsidian.min.css
+www/styles/reveal.css
+www/styles/reveal-white.css
 www/.well_known
 config/auth.db
 config/has_users

+ 8 - 4
Installer.mk

@@ -41,7 +41,7 @@ prereq-debs:
 	    libfile-copy-recursive-perl libxml-rss-perl libmodule-install-perl libio-string-perl uuid-dev                    \
 	    libmoose-perl libmoosex-types-datetime-perl libxml-libxml-perl liblist-moreutils-perl libclone-perl libpath-tiny-perl \
 		selinux-utils setools policycoreutils-python-utils policycoreutils selinux-basics auditd \
-		pdns-tools pdns-server pdns-backend-sqlite3 libmagic-dev
+		pdns-tools pdns-server pdns-backend-sqlite3 libmagic-dev autotools-dev dh-autoreconf
 
 .PHONY: prereq-perl
 prereq-perl:
@@ -56,9 +56,13 @@ prereq-frontend:
 	mkdir -p www/scripts; pushd www/scripts && curl -L --remote-name-all                        \
 		"https://raw.githubusercontent.com/chalda-pnuzig/emojis.json/master/dist/list.min.json" \
 		"https://raw.githubusercontent.com/highlightjs/cdn-release/main/build/highlight.min.js" \
-		"https://cdn.jsdelivr.net/npm/chart.js"; popd
-	mkdir -p www/styles; cd www/styles && curl -L --remote-name-all \
-		"https://raw.githubusercontent.com/highlightjs/cdn-release/main/build/styles/obsidian.min.css"
+		"https://cdn.jsdelivr.net/npm/chart.js" \
+		"https://github.com/hakimel/reveal.js/blob/master/dist/reveal.js"; popd
+	mkdir -p www/styles; pushd www/styles && curl -L --remote-name-all \
+		"https://raw.githubusercontent.com/highlightjs/cdn-release/main/build/styles/obsidian.min.css" \
+	    "https://raw.githubusercontent.com/hakimel/reveal.js/master/dist/reveal.css" \
+		"https://raw.githubusercontent.com/hakimel/reveal.js/master/dist/theme/white.css"; popd
+	mv www/styles/white.css www/styles/reveal-white.css
 
 .PHONY: reset
 reset: reset-remove install

+ 1 - 0
Makefile.PL

@@ -71,6 +71,7 @@ WriteMakefile(
     'DNS::Unbound'              => '0',
     'Net::IP'                   => '0',
     'File::LibMagic'            => '0',
+    'Linux::Perl::inotify'      => '0',
   },
   test => {TESTS => 't/*.t'}
 );

+ 3 - 2
Readme.md

@@ -48,7 +48,7 @@ See migrate.pl, and modify the $docroot variable appropriately
 Content Types
 =============
 Content templates are modular.
-Add in a template to /templates/forms which describe the content *and* how to edit it.
+Add in a template to www/templates/html/components/forms which describe the content *and* how to edit it.
 Our post data storage being JSON allows us the flexibility to have any kind of meta associated with posts, so go hog wild.
 
 Currently supported:
@@ -57,9 +57,10 @@ Currently supported:
 * Files (Video/Audio/Images/Other)
 * About Pages
 * Post Series
+* Presentations
 
 Planned development:
-* Presentations
+* LaTeX
 * Test Plans / Issues (crossover with App::Prove::Elasticsearch)
 
 Embedding Posts within other Posts

+ 1 - 0
lib/TCMS.pm

@@ -71,6 +71,7 @@ sub _app {
     # Make sure all writes are with the proper permissions, none need know of our love
     umask 0077;
 
+    INFO("TCMS starting up on PID $MASTER_PID, Worker PID $$");
     # Start the server timing clock
     my $start = [gettimeofday];
 

+ 36 - 0
lib/Trog/Autoreload.pm

@@ -0,0 +1,36 @@
+package Trog::Autoreload;
+
+use strict;
+use warnings;
+
+use feature qw{signatures};
+
+use Linux::Perl::inotify;
+
+use Trog::Utils;
+
+sub watch_for_changes ( $dir, $interval=5 ) {
+    my $inf = Linux::Perl::inotify->new([qw{NONBLOCK}]);
+ 
+    my @dirs = ($dir);
+    my @wds;
+    foreach my $directory (@dirs) {
+        # Recursive scan for directories and setting up inotifies
+        push(@dirs, _readdir( $directory ));
+        DEBUG("Watching $directory for changes");
+        push(@wds, $inf->add( path => $directory, events => [qw{CREATE MODIFY}] ));
+    }
+    while (!$inf->read()) {
+        sleep $interval;
+    }
+    INFO("Change in $dir detected");
+    Trog::Utils::restart_parent();
+    exit 0;
+}
+
+sub _readdir ( $dir ) {
+    opendir(my $dh, $dir);
+    my @dirs = grep { -d $_ && !m/^\.+$/ } readdir($dh);
+    closedir($dh);
+    return @dirs;
+}

+ 1 - 0
lib/Trog/FileHandler.pm

@@ -26,6 +26,7 @@ sub serve ( $fullpath, $path, $start, $streaming, $ranges, $last_fetch = 0, $def
 
     my $ct      = 'Content-type';
     my @headers = ( $ct => $ft );
+    DEBUG("$ct : $ft");
 
     #TODO use static Cache-Control for everything but JS/CSS?
     push( @headers, 'Cache-control' => $Trog::Vars::cache_control{revalidate} );

+ 5 - 0
www/server.psgi

@@ -6,7 +6,12 @@ use warnings;
 #Grab our custom routes
 use FindBin::libs;
 use TCMS;
+use Trog::Autoreload;
+
+our $MASTER_PID = $$;
 
 $ENV{PSGI_ENGINE} //= 'starman';
 
 our $app = \&TCMS::app;
+
+# TODO Fork off the supervisor process Trog::Autoreload

+ 40 - 0
www/templates/html/components/forms/presentation.tx

@@ -0,0 +1,40 @@
+<div class="post <: $style :>">
+    :if ( !$post.addpost ) {
+        : include "post_title.tx";
+        : include "post_tags.tx";
+
+        : if ( !$post.video_href && !$post.is_image && !$post.is_video && !$post.is_profile && $post.preview ) {
+            <img src="<: $post.preview :>" class="responsive-img" />
+        : }
+
+
+    	<div class="reveal postData responsive-text" id="postData-<: $post.id :>">
+      		<div class="slides">
+      			<: for $post.data -> slide { :>
+      				<section>
+                        <: render_it($slide) | mark_raw  :>
+                    </section>
+      			<: } :>
+      		</div>
+    	</div>
+    	<script src="scripts/reveal.js"></script>
+    	<script>
+      		Reveal.initialize();
+    	</script>
+    : }
+
+    : if ( $can_edit ) {
+        <div class="postedit">
+        : include "edit_head.tx";
+        <form class="Submissions" action="/post/save" method="POST" enctype="multipart/form-data">
+            Title *<br /><input required class="cooltext" type="text" name="title" placeholder="Iowa Man Destroys Moon" value="<: $post.title :>" />
+            : include "preview.tx";
+            : include "visibility.tx";
+            : include "acls.tx";
+            : include "tags.tx";
+            : include "form_common.tx";
+        </form>
+        : include "edit_foot.tx";
+        </div>
+    : }
+</div>

+ 6 - 0
www/templates/html/components/header.tx

@@ -46,6 +46,12 @@
         <!-- For highlight.js !-->
         <link rel="preload" type="text/css" href="/styles/obsidian.min.css" as="style" />
         <link rel="stylesheet" type="text/css" href="/styles/obsidian.min.css" />
+        <!-- For reveal.js !-->
+        <link rel="preload" type="text/css" href="/styles/reveal.css" as="style" />
+        <link rel="stylesheet" type="text/css" href="/styles/reveal.css" />
+        <link rel="preload" type="text/css" href="/styles/reveal-white.css" as="style" />
+        <link rel="stylesheet" type="text/css" href="/styles/reveal-white.css" />
+
         <!-- Javascript !-->
         : for $scripts -> $script {
         <script type="text/javascript" src="<: $script :>"></script>

+ 1 - 0
www/templates/html/components/posts.tx

@@ -36,6 +36,7 @@
     </div>
 : }
 <script type="text/javascript" src="/scripts/highlight.min.js"></script>
+<script type="text/javascript" src="/scripts/reveal.js"></script>
 <script>
 document.addEventListener("DOMContentLoaded", function(){
     hljs.highlightAll();