Browse Source

Fetch content requirements

James Peret 3 years ago
parent
commit
5355678984

+ 2 - 1
.gitignore

@@ -9,4 +9,5 @@ package-lock.json
 source/_posts/blog/
 source/_posts/projects/
 source/images/hero/
-source/images/thumbnails/
+source/images/thumbnails/
+source/images/

+ 26 - 8
fetch-content.js

@@ -10,8 +10,13 @@ var hasArg = function(arg){
 }
 
 var isVerbose = function(){
-    if(hasArg('-v') || hasArg('--verbose')) return true;
-    else return false;
+    if(hasArg('-v') || hasArg('--verbose')) {
+        global.isVerbose = true;
+        return true;
+    } else {
+        global.isVerbose = false;
+        return false;
+    } 
 }
 
 if(hasArg('help') || hasArg('-h')) {
@@ -20,18 +25,31 @@ if(hasArg('help') || hasArg('-h')) {
     console.log();
     console.log('Copy files from codex to build the website content.');
     console.log();
-    console.log(chalk.bold('   Command          Description'));
-    console.log('   projects         Copy projects from Codex');
-    console.log('   posts            Copy blog posts from Codex');
-    console.log('   -v, --verbose    Log all output');
+    console.log(chalk.bold('   Command            Description'));
+    console.log('   projects           Copy projects from Codex');
+    console.log('   posts              Copy blog posts from Codex');
+    console.log('   test               Test requirements for all projects');
+    console.log('   test <project>     Test requirements for a specific project');
+    console.log('   -v, --verbose      Log all output');
     console.log();
     console.log();
     return;
 }
 
+if(hasArg('test')){
+    if(isVerbose()) console.log('Checking requirements:');
+    var query = ""
+    for (let i = 3; i < process.argv.length; i++) {
+        if (process.argv[i] != '-v' && process.argv[i] != '--verbose' ) query += process.argv[i] + " ";
+    }
+    if(query != '') global.isVerbose = true;
+    fetch_projects.showRequirements(query.replace(/\s+$/, ''))
+    return;
+}
+
 if(hasArg('projects')) {
     if(isVerbose()) console.log('Copying projects from Codex');
-    fetch_projects();
+    fetch_projects.all();
     return;
 }
 
@@ -41,4 +59,4 @@ if(hasArg('posts')) {
 }
 
 if(isVerbose()) console.log('Copying projects and blog posts from Codex');
-fetch_projects();
+fetch_projects.all();

+ 114 - 31
fetch-scripts/fetch-projects.js

@@ -1,51 +1,98 @@
 var fs = require('fs')
+
+var utilities = require('./utilities');
+
+const chalk = require('chalk');
+const logSymbols = require('log-symbols');
+
 const YAML = require('json-to-pretty-yaml');
 const TurndownService = require('turndown');
 var turndownService = new TurndownService()
 
-const getDirectories = source =>
-  fs.readdirSync(source, { withFileTypes: true })
-    .filter(item => item.isDirectory())
-    .map(item => item.name);
-
 var source = "/Users/james/codex/projects"
-var projects = getDirectories(source);
-var project_data = []
-projects.forEach(project => {
+var project_directories = utilities.getDirectories(source);
+var projects = []
+
+// Load Files into JSON object
+project_directories.forEach(project => {
     try {
-        project_data.push(JSON.parse(fs.readFileSync(`${source}/${project}/project.json`)));
+        projects.push(JSON.parse(fs.readFileSync(`${source}/${project}/project.json`)));
     } catch(err){}
 });
 
-var copyFile = function(original_path, destination_path){
-    try {    
-        fs.copyFileSync(original_path, destination_path);
-        return true;
-    } catch (err){
-        if(err.code == 'ENOENT'){
-            console.log(`> ERROR: File not found! (\'${original_path}\')`)
-        } else {
-            console.log(err);
-        }
-        return false;
+var hasRequirements = function(project){
+    var requirements = {
+        is_public : project.visibility == "private" || project.visibility == undefined,
+        has_thumbnail : utilities.fileExists( `${source}/${project.permalink}/${project.cover_image}`),
+        has_hero_img : utilities.fileExists(`${source}/${project.permalink}/${project.hero_image}`),
+        has_description : project.description != "" && project.description != undefined,
+        has_text : project.text != "" && project.text != undefined,
+        has_videos : countVideos(project) > 0,
+        has_screenshots : countScreenshots(project) > 0
+    }
+    var pass = ''
+    if(!requirements.is_public) pass = 'no'
+    else if(!requirements.has_thumbnail) pass = 'no'
+    else if(!requirements.has_description) pass = 'no'
+    else if(!requirements.has_hero_img && !requirements.has_videos) pass = 'no'
+    else if(!requirements.has_text) pass = 'some'
+    else if(!requirements.has_videos && !requirements.has_screenshots) pass = 'some'
+    else pass = 'all';
+    requirements.pass = pass;
+    return requirements;
+}
+
+var requirementMessages = function(project, requirements){
+    var warning_thumbnail =   chalk.red(`  - Missing the thumbnail image`);
+    var warning_hero_img =    chalk.red(`  - Missing hero image or video`);
+    var warning_description = chalk.red(`  - Missing description`);
+    var warning_text =        chalk.yellow(`  - Missing long text description`);
+    var warning_screenshots = chalk.yellow(`  - Missing screenshots`);
+    if(global.isVerbose){
+        if(!requirements.has_thumbnail) console.log(warning_thumbnail);
+        if(!requirements.has_description) console.log(warning_description);
+        if(!requirements.has_hero_img && !requirements.has_videos) console.log(warning_hero_img);
+        if(!requirements.has_text) console.log(warning_text);
+        if(!requirements.has_videos && !requirements.has_screenshots) console.log(warning_screenshots);
+    }
+}
+
+var countVideos = function(project){
+    if(project.videos != undefined){
+        return project.videos.length;
+    } else {
+        return 0;
+    }
+}
+
+var countScreenshots = function(project){
+    if(project.screenshots != undefined){
+        return project.screenshots.length;
+    } else {
+        return 0;
     }
 }
 
 var createProject = function(project){
-    // Don't copy private projects
-    if(project.visibility == "private") return;
+    var requirements = hasRequirements(project);
+    //console.log(`${project.title} ${hasRequirements}`)
+    if(requirements.pass == 'no'){
+        console.log(logSymbols.error, `Error creating project \'${chalk.bold(project.permalink)}\'`);
+        requirementMessages(project, requirements);
+        return;
+    }
     // Copy thumbnail
     var cover_path = `${source}/${project.permalink}/${project.cover_image}`
     var cover_ext = project.cover_image.split(".")[1];
     var thumbnail_destination = `source/images/thumbnails/projects/${project.permalink}.${cover_ext}`
-    if(!copyFile(cover_path, thumbnail_destination)) return;
+    if(!utilities.copyFile(cover_path, thumbnail_destination)) return;
     // Copy Hero
     var hero_path, hero_ext, hero_destination;
     if(project.hero_image != undefined){
         hero_path = `${source}/${project.permalink}/${project.hero_image}`
         hero_ext = project.hero_image.split(".")[1];
         hero_destination = `source/images/hero/projects/${project.permalink}.${hero_ext}`
-        copyFile(hero_path, hero_destination);
+        utilities.copyFile(hero_path, hero_destination);
     }
     // Copy screenshots
     var screenshot_data = []
@@ -56,7 +103,7 @@ var createProject = function(project){
                 screenshot_path = `${source}/${project.permalink}/${screenshot.url}`
                 screenshot_ext = project.hero_image.split(".")[1];
                 screenshot_destination = `/images/${project.permalink}-screenshot-${i}.${screenshot_ext}`
-                copyFile(screenshot_path, 'source' + screenshot_destination);
+                utilities.copyFile(screenshot_path, 'source' + screenshot_destination);
                 screenshot.url = screenshot_destination;
                 screenshot_data.push(screenshot)
             }
@@ -90,7 +137,8 @@ var createProject = function(project){
         if(screenshot_data.length > 0) data.screenshots = screenshot_data;
         file += YAML.stringify(data);
     } catch (err){
-        console.log(err);
+        if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
+        if(global.isVerbose) console.log(err);
     }
     file += "---\n";
     if(project.text == undefined){
@@ -102,17 +150,52 @@ var createProject = function(project){
     var project_file_path = `source/_posts/projects/${project.permalink}.md`
     try {
         fs.writeFileSync(project_file_path, file);
-        console.log(`> Created file \'${project.permalink}.md\'`);
+        if(requirements.pass == 'all') {
+            console.log(logSymbols.success, `Created Project \'${chalk.bold(project.permalink)}\'`);
+        } else if(requirements.pass == 'some') {
+            console.log(logSymbols.warning, `Created Project \'${chalk.bold(project.permalink)}\' with warnings`);
+            requirementMessages(project, requirements);
+        }
         counter += 1;
     } catch (err){
-        console.log(err);
+        if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
+        if(global.isVerbose) console.log(err);
     }
 }
+
 var counter = 0;
 
-module.exports = function(){
-    project_data.forEach(project => {
+module.exports.all = function(){
+    projects.forEach(project => {
         createProject(project);
     });
-    console.log(`Copied ${counter}/${project_data.length} projects`);
+    console.log(`Copied ${counter}/${projects.length} projects`);
+}
+
+module.exports.showRequirements = function(query){
+    if(query != undefined) query = query.toLowerCase();
+    var result = [ 0, 0, 0]
+    console.log();
+    projects.forEach(project => {
+        if(project.title.toLowerCase() == query || project.permalink == query || query == ""){
+            var requirements = hasRequirements(project);
+            if(requirements.pass == 'all'){
+                result[0] += 1;
+                console.log(logSymbols.success, 
+                    `Project \'${chalk.bold(project.permalink)}\' has all requirements`);
+            } else if (requirements.pass == 'some') {
+                result[1] += 1;
+                console.log(logSymbols.warning, 
+                    `Project \'${chalk.bold(project.permalink)}\' has some requirements`);
+            } else if(requirements.pass == 'no') {
+                result[2] += 1;
+                console.log(logSymbols.error, 
+                    `Project \'${chalk.bold(project.permalink)}\' doesn\'t have necessary requirements`);
+            }
+            requirementMessages(project, requirements);
+        }
+    });
+    console.log();
+    if(query == "")
+        console.log(chalk.green(`${result[0]} passed`) + ", " + chalk.yellow(`${result[1]} passed with warnings`) + ", " + chalk.red(`${result[2]} missing requirements`));
 }

+ 31 - 0
fetch-scripts/utilities.js

@@ -0,0 +1,31 @@
+var fs = require('fs')
+const chalk = require('chalk');
+const logSymbols = require('log-symbols');
+
+module.exports.copyFile = function(original_path, destination_path){
+    try {    
+        fs.copyFileSync(original_path, destination_path);
+        return true;
+    } catch (err){
+        if(err.code == 'ENOENT'){
+            if(global.isVerbose) { 
+                console.log(logSymbols.error, chalk.red(`ERROR: File not found: \'${original_path}\'`))
+            }
+        } else {
+            if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
+            if(global.isVerbose) console.log(err);
+        }
+        return false;
+    }
+}
+
+module.exports.getDirectories = function(source) {
+    return fs.readdirSync(source, { withFileTypes: true })
+        .filter(item => item.isDirectory())
+        .map(item => item.name);
+}
+
+module.exports.fileExists = function(path){
+    if (fs.existsSync(path)) return true;
+    else return false;
+}

+ 31 - 7
readme.md

@@ -8,7 +8,7 @@ Based on [Hexo](http://hexo.io) for building the static website.
 
 - [ ] Website Tasks
   
-  - [ ] Better home page posts 
+  - [x] Better home page posts 
   
   - [ ] Projects page header
   
@@ -16,9 +16,9 @@ Based on [Hexo](http://hexo.io) for building the static website.
   
   - [ ] Featured projects button
   
-  - [ ] About page content
+  - [ ] **About page content**
   
-  - [ ] Add anv links to home page header
+  - [ ] Add nav links to home page header
   
   - [ ] Filter projects using URL parameters
   
@@ -31,20 +31,26 @@ Based on [Hexo](http://hexo.io) for building the static website.
   - [ ] Tags and category links
   
   - [ ] Tag list filter button in projects page
+  
+  - [x] Move video resizing script outside of page body
 
 - [ ] System Tasks
   
-  - [ ] Thumbnail and hero images are stored in project folder
+  - [x] **Don't copy projects with missing requirements**
+  
+  - [ ] **Thumbnail and hero images are stored in project folder**
   
-  - [ ] Publish upload script
+  - [ ] **Publish upload script**
   
   - [ ] Contact form sends email
   
-  - [ ] Screenshot thumbnail resizing
+  - [ ] **Screenshot thumbnail resizing**
   
-  - [ ] Project downloadable files
+  - [ ] **Project downloadable files**
   
   - [ ] redirect to jamesperet.j1x.co
+  
+  - [ ] video link test requirement
 
 - [ ] Update Content
   
@@ -65,6 +71,24 @@ Based on [Hexo](http://hexo.io) for building the static website.
   - [ ] BattleScape screenshots
   
   - [ ] Add project vertentes.tv
+  
+  - [ ] Add project whois-server
+  
+  - [ ] Add project auto-video
+  
+  - [ ] Add project sozinho
+  
+  - [ ] Add project o-outro
+  
+  - [ ] Add project alo
+  
+  - [ ] Fix solar-wave project data
+  
+  - [x] Fix star-fighter project data
+  
+  - [ ] Add project Julgamento Absurdista
+  
+  - [ ] Add project Anarco-experimentalismo
 
 ### Extras
 

+ 22 - 0
themes/james-theme/layout/_partial/content-card.ejs

@@ -0,0 +1,22 @@
+<div class="col-<%- size %>">           
+    <div class="card <%= post.layout %>">
+        <a href="<%= url_for(post.path) %>" class="text-decoration-none">
+            <img class="img-fluid" src="<%= image %>">
+            <div class="card-body">
+                <h5 class="card-title"><%= post.title %></h5>
+                <% if(post.description == "" || post.description == undefined) { %>
+                    <p class="text-muted">
+                        <i><%= timeAgo(new Date(post.date)) %></i>
+                    </p>
+                <% } else { %>
+                    <p><%= post.description %></p>
+                <% } %>
+            </div>
+            <% if(post.description != "" && post.description != undefined) { %>
+                <div class="card-footer text-muted">
+                    <i><%= timeAgo(new Date(post.date)) %></i>
+                </div>
+            <% } %>
+        </a>
+    </div>
+</div>

+ 3 - 3
themes/james-theme/layout/_partial/content-thumbnail.ejs

@@ -1,11 +1,11 @@
 <% var thumbnail %>
 <% if(post.cover != undefined) thumbnail = post.cover %>
 <% if(post.image != undefined) thumbnail = `/images/thumbnails/blog/${post.image.feature}` %>
+<% if(size == 12) thumbnail = `/images/hero/projects/${post.folder}.jpg` %>
 
-
-<div class="col-3" style="margin-bottom: 30px;">
+<div class="col-<%= size %>" style="margin-bottom: 30px;">
     <a href="<%= url_for(post.path) %>" class="thumbnail-link">
-        <img class="img-fluid thumbnail rounded" src="<%= thumbnail %>">
+        <img class="img-fluid thumbnail thumbnail-col<%= size %> rounded" src="<%= thumbnail %>">
         <% if(show_title == true || show_title == undefined) { %>
             <p><%= post.title %></p>
         <% } %>   

+ 8 - 2
themes/james-theme/layout/_partial/screenshots.ejs

@@ -1,9 +1,15 @@
+<% var size = 4; %>
 <% if(screenshots.length > 0) { %>
     <div class="row up-spacer">
         <% for (let i = 0; i < screenshots.length; i++) { %>
-            <div class="col-4">
+            <% if(screenshots.length == 4 && i == 0) { size = 12 } %>
+            <% if(screenshots.length == 5 && i == 0) { size = 6 } %>
+            <% if(screenshots.length == 5 && i == 1) { size = 6 } %>
+            <% if(screenshots.length == 4 && i >= 1) { size = 4 } %>
+            <% if(screenshots.length == 5 && i >= 2) { size = 4 } %>
+            <div class="col-<%= size %>" style="margin-bottom: 20px;">
                 <a href="<%= url_for(screenshots[i].url) %>" class="">
-                    <img class="img-fluid screenshot figure-img rounded" src="<%= screenshots[i].url %>">
+                    <img class="img-fluid thumbnail figure-img rounded" src="<%= screenshots[i].url %>">
                 </a>
             </div>
         <% } %>

+ 5 - 12
themes/james-theme/layout/_partial/video-player.ejs

@@ -1,16 +1,9 @@
-<div id="player-container" class="container-fluid" style="background-color: black; height: 650px; padding: 0px;">
+<% var height = 600 %>
+<% if(is_hero) height = 650 %>
+<div class="video-frame container-fluid" style="background-color: black; height: <%= height %>px; padding: 0px;">
     <% if(is_video_provider(url, 'youtube')) { %>
-        <iframe id="video-player" src="<%- youtube_embed_link(url) %>" width="560" height="315" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
+        <iframe class="video-player" src="<%- youtube_embed_link(url) %>" width="560" height="315" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
     <% } else if(is_video_provider(url, 'vimeo')) { %>
-        <iframe id="video-player" src="<%- vimeo_embed_link(url) %>" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
+        <iframe class="video-player" src="<%- vimeo_embed_link(url) %>" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
     <% } %>
-    <script>
-        var container = document.getElementById('player-container')
-        document.getElementById("video-player"). width = container.clientWidth;
-        document.getElementById("video-player"). height = container.clientHeight;
-        window.addEventListener("resize", function(event) {
-            document.getElementById("video-player"). width = container.clientWidth;
-            document.getElementById("video-player"). height = container.clientHeight;
-        })
-    </script>
 </div>

+ 6 - 39
themes/james-theme/layout/blog.ejs

@@ -12,47 +12,14 @@
         <% order_posts(site.posts).forEach(function(page) { %>
             <% i += 1 %>
             <% if(i == 1) { %>
-                <div class="col-12">           
-                    <a href="<%= url_for(page.path) %>" class="text-decoration-none">
-                        <div class="card">
-                            <img class="img-fluid" src="<%= `/images/hero/blog/${page.image.feature}` %>">
-                            <div class="card-body">
-                                <h5 class="card-title"><%= page.title %></h5>
-                                <p class="text-muted">
-                                    <i><%= timeAgo(new Date(page.date)) %></i>
-                                </p>
-                            </div>
-                        </div>
-                    </a>
-                </div>
+                <% var data = { post: page, size: 12, image: `/images/hero/blog/${page.image.feature}` }%>
+                <%- partial('_partial/content-card', data) %>
             <% } else if (i == 2 || i == 3) { %>
-                <div class="col-6">           
-                    <div class="card">
-                        <a href="<%= url_for(page.path) %>" class="text-decoration-none">
-                            <img class="img-fluid" src="<%= `/images/thumbnails/blog/${page.image.feature}` %>">
-                            <div class="card-body">
-                                <h5 class="card-title"><%= page.title %></h5>
-                                <p class="text-muted">
-                                    <i><%= timeAgo(new Date(page.date)) %></i>
-                                </p>
-                            </div>
-                        </a>
-                    </div>
-                </div>
+                <% var data = { post: page, size: 6, image: `/images/thumbnails/blog/${page.image.feature}` }%>
+                <%- partial('_partial/content-card', data) %>
             <% } else { %>
-                <div class="col-4">           
-                    <div class="card">
-                        <a href="<%= url_for(page.path) %>" class="text-decoration-none">
-                            <img class="img-fluid" src="<%= `/images/thumbnails/blog/${page.image.feature}` %>">
-                            <div class="card-body">
-                                <h5 class="card-title"><%= page.title %></h5>
-                                <p class="text-muted">
-                                    <i><%= timeAgo(new Date(page.date)) %></i>
-                                </p>
-                            </div>
-                        </a>
-                    </div>
-                </div>
+            <% var data = {post: page, size: 4, image: `/images/thumbnails/blog/${page.image.feature}` }%>
+                <%- partial('_partial/content-card', data) %>
             <% } %>
         <% }) %>
     </div>

+ 41 - 15
themes/james-theme/layout/index.ejs

@@ -1,3 +1,5 @@
+<% var content = site.posts %>
+
 <div id="cover" class="background-haze">
     <div id="stars"></div>
     <div id="stars-2"></div>
@@ -8,13 +10,6 @@
                 <img class="text-logo" alt="James Peret" src="images/jamesperet-logo-white.png">
             </a>
         </h1>
-        <!-- <div class="link-list">
-        <a href="http://blog.jamesperet.com" class="btn btn-link btn-lg" target="_blank">Projects</a>
-        <a href="http://blog.jamesperet.com" class="btn btn-link btn-lg" target="_blank">Blog</a>
-        <a href="http://blog.jamesperet.com" class="btn btn-link btn-lg" target="_blank">About</a>
-        <a href="http://blog.jamesperet.com" class="btn btn-link btn-lg" target="_blank">Contact</a>
-        </div> -->
-
         <div class="container bottom-spacer">
             <div class="row bottom-spacer-lg">
                 <div class="col-3">
@@ -43,12 +38,14 @@
 <div class="container">
     <div class="row" style="margin-bottom: 15px;">
         <div class="col-12">
-            <h2>Latest Projects</h2>
+            <h2 class="display-4">Latest Projects</h2>
         </div>
     </div>
-    <div class="row">
-        <% limit(featured_projects(site.posts), 4).forEach(function(post){ %>
-            <%- partial('_partial/content-thumbnail', {post: post, show_title: true}) %>
+    <div class="row blog-posts">
+        <% limit(featured_projects(content), 3).forEach(function(post){ %>
+            <% content = remove_from_list(content, post) %>
+            <% var data = {post: post, size: 4, image: post.cover} %>
+            <%- partial('_partial/content-card', data) %>
         <% }) %>
     </div>
     <div class="row justify-content-end" style="text-align: right;">
@@ -56,14 +53,43 @@
             <a role="button" href="/projects" class="btn btn-sm btn-outline-secondary"><i class="fas fa-plus"></i> Projects</a>
         </div>
     </div>
+    <% var games = limit(tagged(content, 'games'), 4) %>
+    <% if(games.length > 0) { %>
+        <div class="row" style="margin-bottom: 15px;">
+            <div class="col-12">
+                <h2 class="display-4">Games</h2>
+            </div>
+        </div>
+        <div class="row">
+            <% games.forEach(function(post){ %>
+                <% if(games.length == 1) { %> 
+                    <%- partial('_partial/content-thumbnail', {post: post, show_title: false, size: 12}) %>
+                <% } else if(games.length == 2) { %>
+                    <%- partial('_partial/content-thumbnail', {post: post, show_title: false, size: 6}) %>
+                <% } else if(games.lenth == 3) { %>
+                    <%- partial('_partial/content-thumbnail', {post: post, show_title: false, size: 4}) %>
+                <% } else { %>
+                    <%- partial('_partial/content-thumbnail', {post: post, show_title: false, size: 3}) %>
+                <% } %>
+                <% content = remove_from_list(content, post) %>
+            <% }) %>
+        </div>
+    <% } %>
+    <div class="row justify-content-end" style="text-align: right;">
+        <div class="col-2">
+            <a role="button" href="/projects" class="btn btn-sm btn-outline-secondary"><i class="fas fa-plus"></i> Projects</a>
+        </div>
+    </div>
     <div class="row up-spacer" style="margin-bottom: 15px;">
         <div class="col-12">
-            <h2>Latest Posts</h2>
+            <h2 class="display-4">Latest Posts</h2>
         </div>
     </div>
-    <div class="row ">
-        <% limit(order_posts(site.posts), 4).forEach(function(post){ %>
-            <%- partial('_partial/content-thumbnail', {post: post, show_title: true}) %>
+    <div class="row blog-posts">
+        <% limit(order_posts(content), 3).forEach(function(post){ %>
+            <% content = remove_from_list(content, post) %>
+            <% var data = {post: post, size: 4, image: `/images/thumbnails/blog/${post.image.feature}`} %>
+            <%- partial('_partial/content-card', data) %>
         <% }) %>
     </div>
     <div class="row justify-content-end bottom-spacer" style="text-align: right;">

+ 1 - 0
themes/james-theme/layout/layout.ejs

@@ -22,5 +22,6 @@
   <script src="/js/vue.js"></script>
   <script src="/js/moment.min.js"></script>
   <script src="/js/vue-tags-input.js"></script>
+  <script src="/js/video-resize.js"></script>
   <%- partial('_partial/vue-app') %>
 </html>

+ 10 - 2
themes/james-theme/layout/project.ejs

@@ -1,6 +1,6 @@
 <% if(page.videos != undefined) { %>
-  <% if(page.videos.length > 0) { %>
-    <%- partial('_partial/video-player', {url: page.videos[0].url}) %>
+  <% if(page.videos.length > 0 && page.hero == undefined) { %>
+    <%- partial('_partial/video-player', {url: page.videos[0].url, is_hero: true}) %>
   <% } %>
 <% } %>
 <% if(page.hero != undefined) { %>
@@ -43,8 +43,16 @@
       </div>
     </div>
   </div>
+  
+  
   <% if(page.screenshots != undefined) { %>
     <%- partial('_partial/screenshots', { screenshots : page.screenshots }) %>
   <% } %>
+
+  <% if(page.videos != undefined) { %>
+    <% if(page.videos.length > 0 && page.hero != undefined) { %>
+      <%- partial('_partial/video-player', {url: page.videos[0].url, is_hero: false}) %>
+    <% } %>
+  <% } %>
 </div>
 <%- //partial('_partial/about-author') %>

+ 1 - 1
themes/james-theme/layout/projects.ejs

@@ -12,7 +12,7 @@
     <div class="row" v-if="view.type == 'thumbnails'">
         <div class="col-3" v-for="project in filteredProjects" style="margin-bottom: 30px;">
             <a v-bind:href="`/projects/${project.folder}`" class="thumbnail-link">
-                <img class="img-fluid thumbnail rounded" v-bind:src="project.cover">
+                <img class="img-fluid thumbnail thumbnail-col3 rounded" v-bind:src="project.cover">
             </a>
         </div>
     </div>

+ 28 - 4
themes/james-theme/scripts/helpers.js

@@ -1,9 +1,10 @@
 
 var get_posts = function(pages){
-    var posts = [];
-    pages.forEach(page => {
+    var posts = []
+    for (let i = 0; i < pages.data.length; i++) {
+        const page = pages.data[i];
         if(page.layout == "post") posts.push(page);
-    });
+    }
     return posts;
 }
 
@@ -54,7 +55,7 @@ hexo.extend.helper.register('order_projects', function(pages){
 });
 
 hexo.extend.helper.register('order_posts', function(pages){
-    var posts = get_posts(pages);
+    var posts = get_posts(pages)
     posts.sort(function(a,b){
         return new Date(b.date) - new Date(a.date);
     });
@@ -86,10 +87,33 @@ hexo.extend.helper.register('featured_projects', function(pages){
     return featured;
 });
 
+hexo.extend.helper.register('tagged', function(pages, search_tag){
+    var tagged = []
+    pages.data.forEach(page => {
+        for (let i = 0; i < page.tags.data.length; i++) {
+            if(page.tags.data[i].name == search_tag) {
+                tagged.push(page);
+                break;
+            }
+        }
+    });
+    //console.log(`Found ${tagged.length} posts with tag \'${search_tag}\' in ${pages.length} posts`);
+    return tagged;
+});
+
 hexo.extend.helper.register('limit', function(pages, limit){
     var list = []
     for (let i = 0; i < pages.length; i++) {
         if(i < limit) list.push(pages[i]);
     }
     return list;
+});
+
+hexo.extend.helper.register('remove_from_list', function(pages, page){
+    var list = { data : [], length : 0 }
+    for (let i = 0; i < pages.length; i++) {
+        if(pages.data[i].title != page.title) list.data.push(pages.data[i]);
+    }
+    list.length = list.data.length;
+    return list;
 });

+ 7 - 2
themes/james-theme/source/css/style.styl

@@ -41,8 +41,6 @@ body {
 .thumbnail {
   background-color: rgba(78, 91, 119, 0.2);
   object-fit: cover; 
-  width: 300px;
-	height: 160px;
   display: block;
   text-decoration: none;
   color: #fff;
@@ -59,6 +57,12 @@ body {
   width: 100%;
 }
 
+.thumbnail-col2   { height: 100px; }
+.thumbnail-col3   { height: 160px; }
+.thumbnail-col4   { height: 200px; }
+.thumbnail-col6   { height: 300px; }
+.thumbnail-col12  { height: 450px; }
+
 .legend{
   text-align: center;
   font-size: 14px;
@@ -241,6 +245,7 @@ img.hero {
 
 .blog-posts.row a { color: black; }
 .blog-posts.row a:hover { color: #4c4949; }
+.blog-posts.row .card-body { height: 120px; }
 
 .thumbnail-link:hover img { 
   box-shadow: 0px 5px 10px rgba(78, 91, 119, 0.4);

+ 13 - 0
themes/james-theme/source/js/video-resize.js

@@ -0,0 +1,13 @@
+
+//var container = document.getElementById('player-container')
+$( ".video-frame" ).each(function( index, container ){
+    $( this ).children(".video-player"). width($( this ).width());
+    $( this ).children(".video-player"). height($( this ).height());
+});
+window.addEventListener("resize", function(event) {
+    console.log(`resizing video: ${$( this ).width()}x${$( this ).height()}px`);
+    $( ".video-frame" ).each(function( index, container ){
+        $( this ).children(".video-player"). width($( this ).width());
+        $( this ).children(".video-player"). height($( this ).height());
+    });
+})