mirror of https://github.com/writeas/writefreely
A focused writing and publishing space.
https://write.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
{{define "import"}}
|
|
{{template "header" .}}
|
|
<style>
|
|
input[type=file] {
|
|
padding: 0;
|
|
font-size: 0.86em;
|
|
display: block;
|
|
margin: 0.5rem 0;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin: 1em 0;
|
|
}
|
|
</style>
|
|
|
|
<div class="snug content-container">
|
|
<h1 id="import-header">Import posts</h1>
|
|
{{if .Message}}
|
|
<div class="alert {{if .InfoMsg}}info{{else}}success{{end}}">
|
|
<p>{{.Message}}</p>
|
|
</div>
|
|
{{end}}
|
|
{{if .Flashes}}
|
|
<ul class="errors">
|
|
{{range .Flashes}}<li class="urgent">{{.}}</li>{{end}}
|
|
</ul>
|
|
{{end}}
|
|
<p>Publish plain text or Markdown files to your account by uploading them below.</p>
|
|
<div class="formContainer">
|
|
<form id="importPosts" class="prominent" enctype="multipart/form-data" action="/api/me/import" method="POST">
|
|
<label>Select some files to import:
|
|
<input id="fileInput" class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
|
</label>
|
|
<input id="fileDates" name="fileDates" hidden/>
|
|
<label>
|
|
Import these posts to:
|
|
<select name="collection">
|
|
{{range $i, $el := .Collections}}
|
|
<option value="{{.Alias}}" {{if eq $i 0}}selected{{end}}>{{.DisplayTitle}}</option>
|
|
{{end}}
|
|
<option value="">Drafts</option>
|
|
</select>
|
|
</label>
|
|
<script>
|
|
// timezone offset in seconds
|
|
const tzOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
const fileInput = document.getElementById('fileInput');
|
|
const fileDates = document.getElementById('fileDates');
|
|
fileInput.addEventListener('change', (e) => {
|
|
const files = e.target.files;
|
|
let dateMap = {};
|
|
for (let file of files) {
|
|
// convert from milliseconds to seconds and adjust for tz
|
|
dateMap[file.name] = Math.round(file.lastModified / 1000) + tzOffsetSec;
|
|
}
|
|
fileDates.value = JSON.stringify(dateMap);
|
|
})
|
|
</script>
|
|
<input type="submit" value="Import" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
{{template "footer" .}}
|
|
{{end}}
|
|
|