Skip to content

Commit

Permalink
feat: タグ付き投稿に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
hidao80 committed Apr 29, 2018
1 parent 610980e commit e16455a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
11 changes: 10 additions & 1 deletion src/css/tsumiqiita.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ html,body {
margin: 0;
width: calc(100vw - 2px);
}
#tags-label {
font-size: 1rem;
width: 3rem;
}
#tags {
border: 1px solid darkgray;
margin: 0;
width: calc(100vw - 22px - 3rem);
}
#tsumiqiita-editor {
overflow-x: hidden;
overflow-y: scroll;
border: 1px solid darkgray;
height: calc(50vh - 2px);
height: calc(50vh - 2px - 1.1rem);
margin: 0;
resize: none;
width: calc(100vw - 22px);
Expand Down
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</dialog>
</div>
<div>
<dialog id="ng-dalog">
<dialog id="ng-dialog">
限定公開に失敗しました…<br>
<button onclick="document.querySelector('#ng-dialog').close()">閉じる</button>
</dialog>
Expand All @@ -52,6 +52,7 @@
</div data-comment="end controls">
<div>
<div id="preview" class="markdown-content"></div>
<lable for="tags" id="tags-label">タグ:</lable><input type="text" id="tags" placeholder="タグを入力してください">
<textarea id="tsumiqiita-editor" oninput="rerendaring()"></textarea>
</div>
<script src="./js/functions.js"></script>
Expand Down
30 changes: 20 additions & 10 deletions src/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ function setToken() {
config.set("TOKEN", document.querySelector('#input').value);
}

function getTags() {
const text = document.querySelector("#tags").value;
let ret = [];
let tags = text.trim().split(" ");

for(let i = 0; i < tags.length; i++) {
tmp = tags[i].split(":");
if (tmp.length < 2) {
ret.push({"name":tmp[0]});
} else {
ret.push({"name":tmp[0], "versions": [tmp[1]]});
}
}
console.log(JSON.stringify(ret));
return ret;
}

function post() {
const Config = require('electron-config');
const config = new Config();
Expand All @@ -159,25 +176,18 @@ function post() {
let markdown = fs.readFileSync(p, 'utf-8');

let title = filename.replace(/(\.md)+$/,"");

var options = {
"body": markdown,
"private": true,
"tags": [
{
"name": "TsumiQiita",
"versions": [
"1.2.0"
]
}
],
"tags": getTags(),
"title": title
};

//execution api
Qiita.Resources.Item.create_item(options).then(function(res){
console.log(res);
if (parseInt(res.statusCode, 10) >= 400) {
if (res.message != undefined) {
document.querySelector('#ng-dialog').showModal();
} else {
document.querySelector('#ok-dialog').showModal();
Expand Down
4 changes: 3 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"scripts": {
"build-css": "node-sass scss/default-theme.scss css/style.css",
"build-win": "electron-packager . TsumiQiita --out=../build --pratform=win32 --arch=ia32 --overwrite --asar",
"build-win": "electron-packager . TsumiQiita --out=../build --pratform=win32 --overwrite --asar",
"build-win32": "electron-packager . TsumiQiita --out=../build --pratform=win32 --arch=ia32 --overwrite --asar",
"build-win64": "electron-packager . TsumiQiita --out=../build --pratform=win32 --arch=x64 --overwrite --asar",
"build-mac": "electron-packager . TsumiQiita --out=../build --pratform=darwin --arch=x64 --overwrite --asar",
"build-linux": "electron-packager . TsumiQiita --out=../build --pratform=linux --arch=ia32 --overwrite --asar",
"build": "electron-packager . TsumiQiita --out=../build --overwrite --asar"
Expand Down

0 comments on commit e16455a

Please sign in to comment.