-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewpost.html
More file actions
88 lines (82 loc) · 3.95 KB
/
Copy pathnewpost.html
File metadata and controls
88 lines (82 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
layout: default
permalink: newpost
---
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<style type="text/css">
#github-logout-warning > div{
display: flex;
flex-direction: row;
align-items: center;
}
#github-logout-warning{
margin-bottom: 1rem;
background-color: #e5acac;
width: 100%;
padding: .5rem;
}
</style>
<h1>New Post</h1>
<div id="github-logout-warning" style="display: none;">
<div>
<div>
<i class="fas fa-exclamation-triangle" style="font-size: 200%; float: left; padding-right: 10px; height: 100%; vertical-align: center;"></i>
</div>
<div>
<strong>You are not logged in to GitHub.</strong><br>
You will need to <a href="https://github.com/login" target="_blank">log in</a> or <a href="https://github.com/join" target="_blank">sign up</a> in order to post.<br>
</div>
</div>
<small>(Ignore this warning if you have an ad blocker or similar extension blocking us from seeing you're logged in.)</small>
</div>
<form name="postdetails" action="#" onsubmit="return form_submitted();" target="_blank">
<input id="posttitle" type="text" placeholder="Title"><br>
<input id="postauthor" type="text" placeholder="Author"><br>
<input id="postcatagories" type="text" placeholder="Catagory"><br>
<input style="margin-bottom: 0;" id="postfile" type="url" placeholder="URL to attachment"><br>
<small>Must be a complete URL (ie <code class="highlighter-rouge">https://example.com</code> not <code class="highlighter-rouge">example.com</code>)</small>
<textarea id="newpost"></textarea>
<input type="submit" name="submit" value="Create post">
</form>
<br>
<p>If you do not have permissions to edit the DarbyCAT website, you will have to make a pull request for your post to be reviewed before publishing.</p>
<p>When you click "create post", it should take you to this page:</p>
<img src="{{site.baseurl}}/assets/img/branch.png" alt="You need to fork this repository to make changes">
<p>Click "fork this repository and make changes."</p>
<img src="{{site.baseurl}}/assets/img/commit.png" alt="Propose new file">
<p>Next click propose new file. <small>Hint: if it's grayed out, type something into the file contents and delete it.</small></p>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment-with-locales.min.js"></script>
<script>
var simplemde = new SimpleMDE({ element: $("#newpost")[0], showIcons: ["code", "table"], placeholder: "Post content"});
function github_detect() {
var img = document.createElement('img');
img.src = 'https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffavicon.ico%3Fid%3D1';
img.onerror = function() {
document.getElementById('github-logout-warning').style.display = 'inline-block';
};
}
github_detect();
function form_submitted() {
var postdata = '---\nlayout: post\ntitle: ';
postdata += JSON.stringify($('#posttitle').val());
postdata += '\ndate: ';
postdata += moment(new Date()).format('YYYY-MM-DD HH:mm:ss ZZ');
postdata += '\ncategories: ';
postdata += $('#postcatagories').val();
postdata += '\nauthor: ';
postdata += $('#postauthor').val();
postdata += '\nfilename: ';
postdata += $('#postfile').val();
postdata += '\n---\n';
postdata += simplemde.value();
var filename = '_posts/' + moment(new Date()).format('YYYY-MM-DD-') + $('#posttitle').val().replace(/[^a-zA-Z0-9]/g, '-') + ".markdown";
var message = 'Create new post: "' + $('#posttitle').val().replace(/[^a-zA-Z0-9]/g, '-') + '"';
var description = '\n\nCommited using the New Post tool on the website.';
var url = 'https://github.com/darbycat/new-site/new/master?filename=' + encodeURIComponent(filename) + '&value=' + encodeURIComponent(postdata) + '&message=' + encodeURIComponent(message) + '&description=' + encodeURIComponent(description);
window.location.href = url;
// console.log(url);
// stops the page from reloading afterwards
return false;
}
</script>