Browse Source

Merge branch 'feat/qiita-importer' into feat/importer-qiita

yusuketk 7 years ago
parent
commit
355f27e001

+ 1 - 1
lib/models/page.js

@@ -410,7 +410,7 @@ module.exports = function(crowi) {
 
 
   pageSchema.statics.isCreatableName = function(name) {
   pageSchema.statics.isCreatableName = function(name) {
     var forbiddenPages = [
     var forbiddenPages = [
-      /\^|\$|\*|\+|#/,
+      /\^|\$|\*|\+|#|%/,
       /^\/-\/.*/,
       /^\/-\/.*/,
       /^\/_r\/.*/,
       /^\/_r\/.*/,
       /^\/_apix?(\/.*)?/,
       /^\/_apix?(\/.*)?/,

+ 46 - 0
lib/util/restQiitaAPI.js

@@ -0,0 +1,46 @@
+'use strict';
+
+// Qiita API v2 documant https://qiita.com/api/v2/docs
+
+const https = require('https');
+const team = 'team';
+const token = 'token';
+
+var options = {
+  protocol: 'https:',
+  host: `${team}.qiita.com`,
+  method: 'GET',
+  headers: {
+    'Content-Type': 'application/json',
+    'authorization': `Bearer ${token}`
+  }
+};
+
+function restAPI(path) {
+  options.path = `/api/v2/${path}`;
+  const req = https.request(options, (res) => {
+      res.on('data', (chunk) => {
+          console.log(`${chunk}`);
+          return chunk;
+      });
+  })
+
+  req.on('error', (e) => {
+    console.error(`problem with request: ${e.message}`);
+  });
+
+  req.end();
+};
+
+return {
+  // tags: restAPI('tags'),
+  // templates: restAPI('templates'),
+  // projects: restAPI('projects'),
+  // users: restAPI('users'),
+  // comments: restAPI(`items/${item_id}/comments`),
+  // project_comments: restAPI(`projects/${project_id}/comments`),
+  // itemreactions: restAPI(`items/${item_id}/reactions`),
+  // comment_reactions: restAPI(`comments/${comment_id}/reactions`),
+  // project_reactions: restAPI(`projects/${project_id}/reactions`),
+  items: restAPI('items')
+}

+ 21 - 0
resource/js/components/HeaderSearchBox/SearchForm.js

@@ -45,6 +45,26 @@ export default class SearchForm extends React.Component {
     }
     }
   }
   }
 
 
+  getHelpElement() {
+    return <table className="table m-1">
+            <caption className="text-left text-primary p-2 mb-2">
+              <h5 className="m-1"><i className="icon-magnifier pr-2 mb-2"/>Search Help</h5>
+            </caption>
+            <tr>
+              <td className="text-right mt-0 pr-2 p-1"><code>keyword</code></td>
+              <th className="mr-2"><h6 className="pr-2 m-0 pt-1">記事名 or 本文に<samp>"keyword"</samp>を含む</h6></th>
+            </tr>
+             <tr>
+              <td className="text-right mt-0 pr-2 p-1"><code>a b</code></td>
+              <th><h6 className="m-0 pt-1">文字列<samp>"a"</samp>と<samp>"b"</samp>を含む (スペース区切り)</h6></th>
+            </tr>
+            <tr>
+              <td className="text-right mt-0 pr-2 p-1"><code>-keyword</code></td>
+              <th><h6 className="m-0 pt-1">文字列<samp>"keyword"</samp>を含まない</h6></th>
+            </tr>
+          </table>;
+  }
+
   onSubmit(query) {
   onSubmit(query) {
     this.refs.form.submit(query);
     this.refs.form.submit(query);
   }
   }
@@ -68,6 +88,7 @@ export default class SearchForm extends React.Component {
               onSubmit={this.onSubmit}
               onSubmit={this.onSubmit}
               emptyLabel={emptyLabel}
               emptyLabel={emptyLabel}
               placeholder="Search ..."
               placeholder="Search ..."
+              promptText={this.getHelpElement()}
             />
             />
             <InputGroup.Button>
             <InputGroup.Button>
               <Button type="submit" bsStyle="link">
               <Button type="submit" bsStyle="link">

+ 2 - 26
resource/js/components/SearchTypeahead.js

@@ -159,7 +159,6 @@ export default class SearchTypeahead extends React.Component {
     const defaultSelected = (this.props.keywordOnInit != '')
     const defaultSelected = (this.props.keywordOnInit != '')
       ? [{path: this.props.keywordOnInit}]
       ? [{path: this.props.keywordOnInit}]
       : [];
       : [];
-    const help = this.getHelpElement();
 
 
     return (
     return (
       <div className="search-typeahead">
       <div className="search-typeahead">
@@ -180,36 +179,12 @@ export default class SearchTypeahead extends React.Component {
           renderMenuItemChildren={this.renderMenuItemChildren}
           renderMenuItemChildren={this.renderMenuItemChildren}
           caseSensitive={false}
           caseSensitive={false}
           defaultSelected={defaultSelected}
           defaultSelected={defaultSelected}
-          promptText={help}
+          promptText={this.props.promptText}
         />
         />
         {restoreFormButton}
         {restoreFormButton}
       </div>
       </div>
     );
     );
   }
   }
-
-  getHelpElement() {
-    // TODO disabled temporary -- 2018.07.20 Yuki Takei
-    return <span>(TBD) Show Help</span>;
-    // return <table className="table table-borderd search-help">
-    //           <caption className="text-center">Search Help</caption>
-    //           <tr>
-    //             <td className="text-center">keyword</td>
-    //             <th>記事名 or カテゴリ or 本文にkeywordを含む</th>
-    //           </tr>
-    //           <tr>
-    //             <td className="text-center">title:keyword</td>
-    //             <th>記事名にkeywordを含む</th>
-    //           </tr>
-    //           <tr>
-    //             <td className="text-center">a b</td>
-    //             <th>文字列aとbを含む(スペース区切り)</th>
-    //           </tr>
-    //           <tr>
-    //             <td className="text-center">-keyword</td>
-    //             <th>文字列keywordを含まない</th>
-    //           </tr>
-    //         </table>;
-  }
 }
 }
 
 
 /**
 /**
@@ -224,6 +199,7 @@ SearchTypeahead.propTypes = {
   emptyLabel:      PropTypes.string,
   emptyLabel:      PropTypes.string,
   placeholder:     PropTypes.string,
   placeholder:     PropTypes.string,
   keywordOnInit:   PropTypes.string,
   keywordOnInit:   PropTypes.string,
+  promptText:      PropTypes.object,
 };
 };
 
 
 /**
 /**

+ 0 - 7
resource/styles/scss/_search.scss

@@ -47,13 +47,6 @@
   }
   }
 }
 }
 
 
-// search help
-.search-help {
-  .search-help, td, th {
-    border: solid 1px gray;
-  }
-}
-
 // top and sidebar input styles
 // top and sidebar input styles
 .search-top, .search-sidebar {
 .search-top, .search-sidebar {
   .search-clear {
   .search-clear {