Mémo de construction d'environnement pour satisfaire le désir

OS X Marverics
Python2.7
virtualenv(virtualenvwrapper)
pip
Sphinx
homebrew
Pandoc
Apache
Kobito.app <= 1.9.2
"Lien de fichier externe" ne peut pas être utilisé temporairement pour la série Kobito 2.0
Dash.app
Alfred.app
Quoi qu'il en soit, préparez un projet Sphinx
$ mkvirtualenv qiitanote #J'utilise virualenvwrapper
(qiitanote)$ pip install Sphinx
(qiitanote)$ mkdir qiitanote
(qiitanote)$ cd qiitanote
(qiitanote)$ sphinx-quickstarpt 
#Vous pouvez entendre différentes choses dans le dialogue, donc si vous répondez un peu, la création est terminée
#essayez de faire du html
(qiitanote)$ make html
# _build/html/Le document HTML est généré ci-dessous
#Désactivez Virtualhost avec Apache et http://qiitanote.dev/alors_build/J'essaye de voir ci-dessous html
#Vérifiez le document(Chrome s'ouvre)
(qiitanote)$ open -a Google\ Chrome.app  http://qiitanote.dev
Structure de répertoire initiale
qiitanote
├── Makefile
├── _build
│   ├── doctrees
│   └── html <-Le HTML est généré ici
├── _static
├── _templates
├── conf.py <-Fichier de configuration Sphinx
└── index.rst
Pandoc Insco
(qiitanote)$ brew install pandoc
Paramètres d'extension
# conf.Réécrire py
#Ajout du contenu suivant
PROJECT_DIR = os.path.dirname(__file__)
sys.path.insert(0, PROJECT_DIR)
sys.path.insert(0, os.path.join(PROJECT_DIR, "libs"))  #Script d'extension installé sous les bibliothèques
extensions += ["sphinxcontrib_markdown"]
markdown_title = 'Qiita Note'
source_suffix = '.md'
Créez un fichier .md et écrivez-le
(qiitanote)$ touch fisrtnote.md
Contenu
# My First Qiita Memo!!!
## 1. Hoge
hogehogehogehoge
hogehogehogehoge
## 2. Fuga
fugafugafugafuga
fugafugafugafuga
Construire
(qiitanote)$ make html
résultat

Faire fonctionner les fichiers avec Kobito pour les publier sur Qiita
(qiitanote)$ open -a Kobito firstnote.md
# -*- coding: utf-8 -*-
import os
import time
import subprocess
TARGET_DIR = os.path.join(os.path.dirname(__file__), '..')
cmd = "open --hide -g -a Kobito {}"
# start Koibito.app
subprocess.call(cmd.format(""), shell=True)
time.sleep(3)
# associate .md file to Koibito.app
for root, dirs, files in os.walk(TARGET_DIR):
    for f in files:
        if f.endswith(".md"):
            f = os.path.abspath(os.path.join(root, f))
            subprocess.call(cmd.format(f), shell=True)
# hyde Kobito.app
subprocess.call(
    "osascript -e 'tell application \"Finder\"'"
    " -e 'set visible of process \"Kobito\" to false'"
    " -e 'end tell'",
    shell=True
)
Exécutez ce script lorsque vous "créez du HTML"
html:
	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
	python libs/associate_kobito.py  # <=ajouter à
	@echo
	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Lorsque vous construisez avec cela, un mémo apparaîtra dans Kobito sans autorisation.
Configuration jusqu'à présent
qiitanote
├── Makefile
├── _build
│   ├── doctrees
│   └── html
├── _static
├── _templates
├── conf.py
├── firstnote.md
├── index.md # <-ajouter à
├── index.rst
└── libs
    ├── associate_kobito.py # <-ajouter à
    └── sphinxcontrib_markdown.py # <-ajouter à
C'est un mémo que j'ai écrit, je veux donc le rechercher facilement à portée de main. Recherche à l'aide d'Alfred et Dash. J'ai acheté Alfred et Dash moyennant des frais.
sphinxcontrib-dashbuilder facilite la transformation de documents Sphinx en Docsets pour Dash
Installation
(qiitanote)$ pip install sphinxcontrib-dashbuilder
Modifier le fichier de paramètres
# conf.py
extensions += ["sphinxcontrib_markdown", "sphinxcontrib.dashbuilder"]
dash_name = 'QiitaNote'
dash_icon_file = '_static/qiita.png' # <-favicon a été correctement apporté de Qiita
Réécriture de Makefile
# You can set these variables from the command line.
SPHINXOPTS    =
SPHINXBUILD   = sphinx-build
PAPER         =
BUILDDIR      = _build
DOCSETSDIR    = ~/Library/Application\ Support/Dash/DocSets/QiitaNote # <-ajouter à
~ abrégé ~
# .Dash ajouté à PHONY
.PHONY: dash help ... 
~ abrégé ~
#Ajouter une cible de tableau de bord
dash:
	$(SPHINXBUILD) -b dash $(ALLSPHINXOPTS) $(DOCSETSDIR)
	@echo
	@echo "Build finished. The Docset are in $(DOCSETSDIR)."
Construire
(qiitanote)$ make dash
Vérifiez avec Dash. Écran des paramètres du tableau de bord> Docsets> Appuyez sur le bouton Rescan

La note Qiita apparaît dans les ensembles de documents de Dash

Il est difficile d'appuyer sur "make dash" à chaque fois, donc build dash même lorsque "make html" est utilisé.
html:
	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
	$(SPHINXBUILD) -b dash $(ALLSPHINXOPTS) $(DOCSETSDIR) # <-ajouter à
	python libs/associate_kobito.py  
	@echo
	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Markdown-> reST Force le titre à indexer pendant la conversion.
## Hoge
## Fuga 
Supposons qu'il existe une telle rubrique. Une fois converti en reST, procédez comme suit.
.. index:: Hoge
Hoge
----
.. index:: Fuga
Fuga
----
Ajoutez le traitement suivant à libs / sphinxcontrib_markdown.py.
48  # insert index directive                                                                
49  newlines = []                                                                           
50  for line in source[0].split(u"\n"):                                                     
51      if self._is_heading_line(line):                                                     
52          prev = newlines[-1]                                                             
53          inedexline = u".. index:: {0}\n".format(prev)
54          newlines.insert(-1, inedexline)                                                 
55      newlines.append(line)
56  source[0] = "\n".join(newlines)
Maintenant, lorsque vous construisez à nouveau, vous pouvez trouver les en-têtes d'Alfred

Configuration jusqu'à présent
qiitanote
├── Makefile
├── _build
│   └── doctrees
├── _static
│   └── qiita.png # <-ajouter à
├── _templates
├── conf.py
├── firstnote.md
├── index.md
├── index.rst
└── libs
    ├── associate_kobito.py
    └── sphinxcontrib_markdown.py
Utilisez mon thème sphinx.
(qiitanote)$ pip install sphinxjp.themes.basicstrap
Modifier les paramètres
# conf.py
extensions += ["sphinxcontrib_markdown", "sphinxcontrib.dashbuilder", 'sphinxjp.themes.basicstrap']
html_theme = 'basicstrap'
html_theme_options = {
    'noheader': True,
    'header_inverse': True,
    'relbar_inverse': True,
    'inner_theme': True,
    'inner_theme_name': 'bootswatch-sandstone',
}
Construire
(qiitanote)$ make html
résultat

C'est un peu différent de ce qui est écrit, mais je l'ai mis sur Github. S'il te plait accepte-le.
https://github.com/tell-k/qiitanote
TODO
Recommended Posts