Browse Source

Added a sitemap generator

pull/4/head
jrtechs 6 years ago
parent
commit
4b09f526ba
8 changed files with 81 additions and 46 deletions
  1. +0
    -6
      .idea/vcs.xml
  2. +3
    -3
      README.md
  3. +2
    -0
      admin/newPost.js
  4. +14
    -6
      package.json
  5. +3
    -1
      server.js
  6. +0
    -17
      sitemap.txt
  7. +28
    -13
      utils/generateSiteMap.js
  8. +31
    -0
      utils/sql.js

+ 0
- 6
.idea/vcs.xml View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 3
- 3
README.md View File

@ -4,9 +4,9 @@ Recreating my Wordpress blog in node JS.
## MYSQL Information
```SQL
create database blog_name;
create database jrtechs_blog;
use blog_name;
use jrtechs_blog;
create table users(
user_id mediumint unsigned not null AUTO_INCREMENT,
@ -46,7 +46,7 @@ post_id mediumint unsigned not null,
primary key(popular_post_id)
);
grant all on blog_name.* to blog_user@localhost identified by "password";
grant all on jrtechs_blog.* to blog_user@localhost identified by "password";
```

+ 2
- 0
admin/newPost.js View File

@ -42,6 +42,8 @@ module.exports=
"', '" + post.add_post_date + "', '" + post.add_post_name + "', '" + urls + "')";
sql.insert(q).then(function()
{
var map = require('../utils/generateSiteMap');
map.main();
resolve();
})
}

+ 14
- 6
package.json View File

@ -1,9 +1,18 @@
{
"name": "jrtechs",
"name": "jrtechs-blog",
"version": "1.0.0",
"description": "Personal blog",
"description": "Personal wordpress replacement",
"main": "server.js",
"dependencies": {},
"dependencies": {
"highlight": "^0.2.4",
"markdown": "^0.5.0",
"markdown-to-html": "^0.0.13",
"mysql": "^2.15.0",
"promise": "^8.0.1",
"sanitizer": "^0.1.3",
"step": "^1.0.0",
"synchronize": "^2.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@ -14,8 +23,7 @@
"url": "git+https://github.com/jrtechs/NodeJSBlog.git"
},
"keywords": [
"nodejs",
"blog"
"nodejs"
],
"author": "Jeffery Russell",
"license": "ISC",
@ -23,4 +31,4 @@
"url": "https://github.com/jrtechs/NodeJSBlog/issues"
},
"homepage": "https://github.com/jrtechs/NodeJSBlog#readme"
}
}

+ 3
- 1
server.js View File

@ -19,8 +19,10 @@ const utils = require('./utils/utils.js');
//
// var forceSsl = require('express-force-ssl');
var app = express();
var map = require('./utils/generateSiteMap');
map.main();
var app = express();
app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }}));

+ 0
- 17
sitemap.txt View File

@ -1,17 +0,0 @@
http://jrtechs.net
http://www.jrtechs.net/programming/using-english-conventions-to-write-clean-code
http://www.jrtechs.net/web-development/node.js-vs-php
http://www.jrtechs.net/other/why-do-i-blog
http://www.jrtechs.net/web-development/history-of-jrtechs
http://www.jrtechs.net/web-development/why-i-stopped-using-wordpress
http://www.jrtechs.net/projects/musical-floppy-drives
http://www.jrtechs.net/projects/java-fibonacci-solver
http://www.jrtechs.net/projects/batch-minecraft-launcher-with-auto-restart
http://www.jrtechs.net/projects/ackermann-function-written-in-java
http://www.jrtechs.net/projects/time-lapse-programming-zombie-game
http://www.jrtechs.net/category/java
http://www.jrtechs.net/category/other
http://www.jrtechs.net/category/projects
http://www.jrtechs.net/category/web-development
http://www.jrtechs.net/category/hardware
http://www.jrtechs.net/category/programming

+ 28
- 13
utils/generateSiteMap.js View File

@ -2,18 +2,33 @@ const fs = require('fs');
const sql = require('../utils/sql');
var stream = fs.createWriteStream("../sitemap.txt");
stream.once('open', function(fd)
module.exports=
{
sql.getSiteMap().then(function(result)
{
stream.write(result);
}).then(function()
{
stream.end();
}).catch(function(err)
main: function()
{
console.log(err);
});
});
sql.getSiteMap().then(function(result)
{
var buf = Buffer.from(result, 'utf8');
var path = '../sitemap.txt';
fs.open(path, 'w', function(error, fd)
{
if(error)
throw 'could not open file: ' + error;
fs.write(fd, buf, 0, buf.length, null, function(err)
{
if(err)
throw "error writing file: " + err;
fs.close(fd, function()
{
console.log("Updated Sitemap");
})
});
});
});
}
}

+ 31
- 0
utils/sql.js View File

@ -276,6 +276,37 @@ module.exports=
{
return new Promise(function(resolve, reject)
{
var base = "http://jrtechs.net/";
var sm = base + "\n";
var promises = [];
module.exports.getCategories().then(function(categories)
{
categories.forEach(function(cat)
{
promises.push(new Promise(function(res, rej)
{
sm += base + "category/" + cat.url + "\n";
module.exports.getPostsFromCategory(cat.url).then(function(posts)
{
posts.forEach(function(post)
{
sm += base + cat.url + "/" + post.url + "\n";
});
res()
})
}));
});
Promise.all(promises).then(function()
{
resolve(sm);
}).catch(function(error)
{
throw error;
});
});
});
}

Loading…
Cancel
Save