-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheditor.html
More file actions
343 lines (316 loc) · 13.3 KB
/
editor.html
File metadata and controls
343 lines (316 loc) · 13.3 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!doctype html>
<!-- https://github.com/paulirish/html5-boilerplate/blob/master/index.html -->
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<!-- meta element for compatibility mode needs to be before
all elements except title & meta
msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx -->
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Pythonjobs online submission editor</title>
<meta name="description" content="The pythonjobs editor page">
<!-- Because we have responsive styles, don't set device-width which makes rotation look weird
and allow users to zoom-in/out as they wish -->
<meta name="viewport" content="initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="76x76" href="/touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="120x120" href="/touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="152x152" href="/touch-icon-ipad-retina.png">
<link rel="apple-touch-icon" sizes="180x180" href="/touch-icon-iphone6.png">
<link href="/atom.xml" type="application/atom+xml" rel="alternate" title="The Free Python Job Board's atom feed" />
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml"/>
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/media/css/font.css">
<link rel="stylesheet" href="/media/css/site.css">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro:400,700" rel="stylesheet">
<link rel="stylesheet" href="/media/css/editor.css">
</head>
<body id="editor">
<header>
<div class="in">
<div id="logo"><a href="/"><i class="i-pyjobslogo"></i></a></div>
<div id="title"><a href="/">The Free <span>Python Job Board</span></a></div>
<div class="sub">for the global Python community</div>
</div>
</header>
<div id="container">
<div id=editor-column>
<h2>Editor</h2>
<div class=infopanel>
<p>Fill in the template below. The preview should auto-update to reflect changes.</p>
<p><em><b>Please note:</b> The preview may not be 100% identical to the final output,
we use a different rendering engine for the live site.</em></p>
<p>Once you're happy with the result, press 'Create pull request' below.<br/>
<em>It helps if you're logged into github already before clicking that button (bug with github).</em><br/>
If the button doesn't work, please copy-paste the <b>editor</b> text as a new file in a Github pull request here:
<a target=_blank href="https://github.com/pythonjobs/jobs/new/master/jobs?filename=.html&value=paste%20here...">https://github.com/pythonjobs/jobs/new/master/jobs</a>
</p>
</div>
<div id=editor-buttons>
<button onclick=reset_saved()>Reset to template</button>
<a id=pr-link target=_blank>Create Pull Request</a>
</div>
<div id=editors>
<textarea id=ad-editor>---
title: # Job Advert Title (required)
company: # Your Company (required)
url: https://... #<Link to your site/a job spec (optional)>
location: # where is the job based? e.g. London,England
# Choose one of the following options
contract: # permanent / contract / part-time / temporary
contact:
name: # Your name (required)
email: # Email address applicants should submit to (required)
phone: # Phone number (optional)
# <additional contact fields>: <additional value>
created: !!timestamp 2018-04-25
tags:
- python
- sql
- django
# include relevant tags
---
# Title
More information about the role...
## Sub-title
Further info</textarea>
</div>
</div>
<div id=preview-column>
<h2>Preview</h2>
<div id=preview></div>
</div>
</div> <!--! end of #container -->
<footer>
<a class="about" href="https://www.github.com/pythonjobs/jobs">
Have a job to advertise? Create a pull-request <i class="i-github"></i>
</a>
The Free Python Job Board - Hosted by
<a href="https://www.github.com/pythonjobs/jobs" target="_blank">github</a>, generated with <a href="http://hyde.github.io/">hyde</a>.
</footer>
<!-- Javascript at the bottom for fast page loading -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<script>window.jQuery || document.write('<script src="/media/js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js"></script>
<!-- CodeMirror -->
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/codemirror.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/codemirror.min.css">
<!-- CodeMirror: Addons -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/addon/lint/lint.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/addon/lint/lint.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/js-yaml/3.11.0/js-yaml.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/addon/mode/overlay.min.js"></script>
<!-- CodeMirror: Modes -->
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/mode/markdown/markdown.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/mode/gfm/gfm.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/mode/yaml/yaml.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/mode/yaml-frontmatter/yaml-frontmatter.min.js"></script>
<!-- Template for preview -->
<script src="//mozilla.github.io/nunjucks/files/nunjucks-slim.js"></script>
<script src="//unpkg.com/dayjs@1.5.12/dist/dayjs.min.js"></script>
<script src="/media/js/job-preview.js"></script>
<script>
'use strict';
if (!String.prototype.padStart) {
String.prototype.padStart = function padStart(targetLength,padString) {
targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
padString = String((typeof padString !== 'undefined' ? padString : ' '));
if (this.length > targetLength) {
return String(this);
}
else {
targetLength = targetLength-this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
}
return padString.slice(0,targetLength) + String(this);
}
};
}
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function(predicate) {
const o = Object(this);
const len = o.length >>> 0;
let k = 0;
while (k < len) {
var kValue = o[k];
if (predicate(kValue)) {
return kValue;
}
k++;
}
return undefined;
},
configurable: false,
writable: false
});
}
function get_ad_parts(text){
let parts = (('\n' + text).split("\n---\n"));
return {meta: parts[1], body: parts[2]};
};
function meta_checks(full_text, errors, meta){
const text_lines = full_text.split('\n');
const loc = CodeMirror.Pos(0,0);
function check(pass, line_finder, msg){
if (!pass){
let error_loc = loc;
for (let line=0; line < text_lines.length; ++line) {
if (text_lines[line].match(line_finder)) {
error_loc = CodeMirror.Pos(line+1, 0);
}
}
errors.push({from: error_loc, to: error_loc, message: msg});
}
}
check((meta.title || '').length > 2, /^\s*title:/, "title must be provided");
check((meta.company || '').length > 1, /^\s*company:/, "company must be provided");
check((meta.location || '').length > 2, /^\s*location:/, "location must be provided");
check(meta.contact, "contact", "Must provide contact info");
meta.contact = meta.contact || {};
check((meta.contact.name || '').length > 2, /^\s*name:/, "contact.name must be provided");
check(
(meta.contact.email || '').match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,10}$/i),
/^\s*email:/,
"valid contact.email must be provided")
check(
(meta.contract || '').match(/(contract|perm|temp|part\-time|other)/i),
/^\s*contract:/,
"contract must be one of contract, perm, temp, part-time or other"
);
check(meta.created || meta.created.getFullYear, /^\s*created:/, "created must be provided and be a valid date");
check(meta.created < new Date(), /^\s*created:/, "created date must not be in the future");
check(!(meta.tags || []).find(function(x){ return (x||'').match(/index/i);}), /^\s*tags:/, "Tags cannot contain index");
}
function frontmatter_lint(text) {
const beginning = CodeMirror.Pos(0,0);
var found = [];
if (!text.match(/^---\n/)) {
found.push({from: beginning, to: beginning, message: "Must start with '---' on first line"});
}
const parts = get_ad_parts(text);
let meta;
try {
meta = jsyaml.load(parts.meta);
} catch(e) {
var loc = e.mark,
// Offset by 1 because of leading '---' line
from = loc ? CodeMirror.Pos(loc.line+1, loc.column) : CodeMirror.Pos(1, 0),
to = from;
found.push({ from: from, to: to, message: e.message });
}
if(!parts.body) {
found.push({from: beginning, to: beginning, message: "Format should be:\n---\nyaml header\n---\nmarkdown body"});
}
if(meta && meta != 'undefined') {
meta_checks(parts.meta, found, meta);
}
return found;
}
function reset_saved() {
window.localStorage.currentJobEditorText = ''
window.location.reload(true);
}
$("#pr-link").click(function(e) {
const full_text = window.meta_codemirror.getValue();
if (frontmatter_lint(full_text).length) {
if (!confirm("There are errors in this document, really continue?")){
e.preventDefault();
e.stopPropagation();
return false;
}
}
});
function iso_date() {
const today = new Date();
const month_str = ('' + (today.getMonth()+1)).padStart(2, '0');
const day_str = ('' + today.getDate()).padStart(2, '0');
return '' + today.getFullYear() + '-' + month_str + '-' + day_str;
}
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
let cur_update_id = null;
function queue_preview_update() {
window.localStorage.currentJobEditorText = window.meta_codemirror.getValue();
if(cur_update_id) {
window.clearTimeout(cur_update_id);
cur_update_id = null;
}
cur_update_id = window.setTimeout(update_preview, 200);
}
function update_pr_link(full_text, meta) {
const base = "https://github.com/pythonjobs/jobs/new/master/?";
const filename = 'jobs/' + slugify('' + meta.company + ' ' + meta.title) + ".html";
const query_params = $.param({filename: filename, value: full_text});
$("#pr-link").attr('href', base + query_params);
};
function update_preview() {
$("#preview").html("loading");
const full_text = window.meta_codemirror.getValue();
try{
let parts = get_ad_parts(full_text);
parts.meta = jsyaml.load(parts.meta);
let c = dayjs(parts.meta.created);
parts.meta.created = {strftime: function(){return c.format("dddd, D MMMM YYYY");}};
let md_converter = new showdown.Converter({noHeaderId: true});
const detail = md_converter.makeHtml(parts.body);
var html = nunjucks.render("job.j2", {
content_url: function() { return '';},
resource: parts,
detail: detail
});
$("#preview").html(html);
update_pr_link(full_text, parts.meta);
}catch(e){
console.log(e);
$("#preview").html("<b>Error generating preview</b>");
return;
}
}
$(function(){
const ad_editor = document.getElementById("ad-editor");
ad_editor.value = ad_editor.value.replace(
/!!timestamp 'XXX'/,
"!!timestamp " + iso_date()
);
window.meta_codemirror = CodeMirror.fromTextArea(ad_editor, {
mode: 'yaml-frontmatter',
lineWrapping: true,
lineNumbers: true,
lint: {getAnnotations: frontmatter_lint},
gutters: ["CodeMirror-lint-markers"],
viewportMargin: Infinity
});
window.meta_codemirror.on('changes', queue_preview_update);
if (localStorage.currentJobEditorText) {
window.meta_codemirror.setValue(localStorage.currentJobEditorText);
}
update_preview()
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59980478-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>