Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
viperadnan-git committed May 4, 2021
1 parent e70ed4f commit 4c8ad16
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 0 deletions.
70 changes: 70 additions & 0 deletions assets/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!doctype html>
<html lang="en">
<head>
<title>codepen</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/images/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicons/favicon-16x16.png">
<link rel="manifest" href="/assets/images/favicons/site.webmanifest">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<style>
.bg-black {
background-color: #333;
}
.navbar {
font-weight: 900;
font-size: 33px;
padding: 0;
}
.navbar-brand {
font-size: 32px;
}
.badge {
font-weight: normal;
font-size: 8px;
padding: 3px 5px 3px 5px;
}
.badge-left {
border-radius: 3px 0 0 3px;
}
.badge-right {
border-radius: 0 3px 3px 0;
background-color: #ededed;
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-black">
<div class="container-fluid">
<span id="heading" class="navbar-brand mb-0 fw-bolder"></span>
</div>
</nav>
<div class="container my-3">
<div id="home"></div>
</div>
<footer id="is-footer" class="d-none d-flex justify-content-center">
<a href="https://viperadnan-git.github.io"><span class="badge bg-black badge-left">viperadnan</span><span class="badge text-dark badge-right">&lt;&sol;&gt;</span></a>
</footer>
<script>
const dogbin_raw_url_prefix = "https://del.dog/raw/";
$.ajax({
method: "GET",
url: String(dogbin_raw_url_prefix) + window.location.pathname
}).done(function(data, textStatus, jqXHR) {
const json_data = JSON.parse(data);
$("#heading").text(json_data.heading);
$("#home").show().html(marked(json_data.home));
document.title = json_data.heading;
if (json_data.footer) {
$("#is-footer").removeClass('d-none');
}
}).fail(function(jqXHR, textStatus, errorThrown) {
window.location.href = "/"
});
</script>
</body>
</html>
Binary file added assets/images/favicons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/favicons/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions assets/images/favicons/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
Binary file added assets/images/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!doctype html>
<html lang="en">
<head>
<title>codepen</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/images/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicons/favicon-16x16.png">
<link rel="manifest" href="/assets/images/favicons/site.webmanifest">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<style>
textarea {
width: 100%;
height: 150px;
}
.bg-black {
background-color: #333;
}
.navbar {
font-weight: 900;
font-size: 33px;
padding: 0;
}
.navbar-brand {
font-size: 32px;
}
:focus {
outline: 0;
outline-color: transparent;
outline-style: none;
}
.badge {
font-weight: normal;
font-size: 8px;
padding:3px 5px 3px 5px;
}
.badge-left {
border-radius: 3px 0 0 3px;
}
.badge-right {
border-radius: 0 3px 3px 0;
background-color: #ededed;
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-black">
<div class="container-fluid">
<span contenteditable="true" id="heading" class="navbar-brand mb-0 fw-bolder">codepen</span>
<button id="save" class="btn btn-dark">
<img width="24" src="assets/images/save.png">
</button>
</div>
</nav>
<div class="container my-3">
<div class="d-flex justify-content-end">
<div class="d-inline-block form-check form-switch mx-auto">
<input class="form-check-input" type="checkbox" id="is-code">
<label class="form-check-label" for="is-code">Paste as Code</label>
</div>
<div class="d-inline-block form-check mx-auto">
<input class="form-check-input" type="checkbox" id="is-footer">
<label class="form-check-label" for="is-footer">Hide Watermark</label>
</div>
</div>
<textarea id="inputext" class="form-control my-2" placeholder="Write something..."></textarea>
<div id="home"></div>
</div>
<footer class="d-flex justify-content-center mb-2">
<a href="https://viperadnan-git.github.io"><span class="badge bg-black badge-left">viperadnan</span><span class="badge text-dark badge-right">&lt;&sol;&gt;</span></a>
</footer>
<script>
const dogbin_api_url = "https://del.dog/documents";
$("#save").click(function() {
$.ajax({
method: "POST",
url: dogbin_api_url,
data: JSON.stringify({
"heading": $("#heading").text(),
"home": $("#is-code").is(":checked") ? "<pre>" + $("#inputext").val() + "<pre>" : $("#inputext").val(),
"footer": $("#is-footer").is(":checked") ? false : true
})
}).done(function(data, textStatus, jqXHR) {
window.location.href = "/" + data.key;
})
});
$("#inputext").keyup(function() {
$("#home").show().html(marked($("#is-code").is(":checked") ? "<pre>" + $("#inputext").val() + "</pre>" : $("#inputext").val()))
});
</script>
</body>
</html>
60 changes: 60 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const port = process.argv[3] || 8080;
const hostname = process.argv[2] || '127.0.0.1';

http.createServer(function (req, res) {
console.log(`${req.method} ${req.url}`);
const parsedUrl = url.parse(req.url);
let pathname = `.${parsedUrl.pathname}`;
const ext = path.parse(pathname).ext;
const map = {
'.ico': 'image/x-icon',
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.css': 'text/css',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.wav': 'audio/wav',
'.mp3': 'audio/mpeg',
'.svg': 'image/svg+xml',
'.pdf': 'application/pdf',
'.doc': 'application/msword'
};
if (pathname == "./") {
fs.readFile('./assets/index.html', function(err, data){
if(err){
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', map[ext] || 'text/html' );
res.end(data);
}
});
} else if (pathname.startsWith("./assets/images")) {
fs.readFile(pathname, function(err, data){
if(err){
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', map[ext] || 'text/html' );
res.end(data);
}
});
} else {
fs.readFile('./assets/blog.html', function(err, data){
if(err){
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', map[ext] || 'text/html' );
res.end(data);
}
});
}
}).listen(parseInt(port), hostname);

console.log(`Server listening on ${hostname}:${port}`);
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "codepen",
"version": "0.1.0",
"description": "A website to render html and markdown codes.",
"main": "index.js",
"scripts": {
"test": "node index.js 127.0.0.1 8080"
},
"repository": {
"type": "git",
"url": "git+https://github.com/viperadnan-git/codepen.git"
},
"keywords": [
"render",
"render-html",
"render-md",
"html",
"markdown",
"pastebin"
],
"author": "viperadnan",
"license": "MIT",
"bugs": {
"url": "https://github.com/viperadnan-git/codepen/issues"
},
"homepage": "https://github.com/viperadnan-git/codepen#readme"
}

0 comments on commit 4c8ad16

Please sign in to comment.