Merge pull request #1 from danger89/master

Improve readme & fix several failures during run-time (errors)
This commit is contained in:
Peter Molnar 2019-04-10 08:19:52 +00:00 committed by GitHub
commit 85eb8324ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 8 deletions

View file

@ -61,6 +61,65 @@ How it works
- fallback - 404 handler to do redirects/gones, gets populated with an array of both - fallback - 404 handler to do redirects/gones, gets populated with an array of both
- micropub - a micropub endpoint that accepts micropub content and puts the incoming payload into a json file, nothing else - micropub - a micropub endpoint that accepts micropub content and puts the incoming payload into a json file, nothing else
## Deploy
### Requirements
For Debian based distributions, install the packages:
* python3
* python3-pip
* pandoc
`sudo apt install python3 python3-pip pandoc`
Install pipenv via pip:
`sudo pip3 install pipenv`
Install the pip dependency packages by using the Pipfile by running:
`pipenv install`
### Prepare
Create a local base directory where your contents will be put into. Eg:
`~/MyWebsite`
Create the following directories within your base directory directory: `www`, `nasg/templates`, `content/home`.
Copy the templates from the `templates` directory to the `~/MyWebsite/nasg/templates` directory.
Create a new file within the root directory called `keys.py` with the following content:
```python
webmentionio = {
'domain': 'yourdomain.com',
'token': 'token',
'secret': 'secret'
}
telegraph = {
'token': 'token'
}
zapier = {
'zapier': 'secret'
}
```
Add an `index.md` file to the `~/MyWebsite/content/home` directory.
Finally, change the [settings.py](settings.py) file, like the `base` path and `syncserver` etc. to your needs.
### Run
Execute within the root folder:
`./run`
For more info, see: `./run -h`.
## Functionalities based on file extensions/names ## Functionalities based on file extensions/names
- **entry_name/index.md**: main entry (YAML + Multimarkdown) - **entry_name/index.md**: main entry (YAML + Multimarkdown)

19
nasg.py
View file

@ -1711,7 +1711,10 @@ class Category(dict):
@property @property
def mtime(self): def mtime(self):
return self[self.sortedkeys[0]].published.timestamp if len (self.sortedkeys) > 0:
return self[self.sortedkeys[0]].published.timestamp
else:
return 0
@property @property
def rssfeedfpath(self): def rssfeedfpath(self):
@ -1759,7 +1762,10 @@ class Category(dict):
[self[k].dt for k in self.sortedkeys[start:end]], [self[k].dt for k in self.sortedkeys[start:end]],
reverse=True reverse=True
) )
return s[0] if len(s) > 0:
return s[0] # Timestamp in seconds since epoch
else:
return 0
@property @property
def ctmplvars(self): def ctmplvars(self):
@ -2071,10 +2077,11 @@ class Sitemap(dict):
return os.path.join(settings.paths.get('build'), 'sitemap.txt') return os.path.join(settings.paths.get('build'), 'sitemap.txt')
async def render(self): async def render(self):
if self.mtime >= sorted(self.values())[-1]: if len(self) > 0:
return if self.mtime >= sorted(self.values())[-1]:
with open(self.renderfile, 'wt') as f: return
f.write("\n".join(sorted(self.keys()))) with open(self.renderfile, 'wt') as f:
f.write("\n".join(sorted(self.keys())))
class WebmentionIO(object): class WebmentionIO(object):

View file

@ -57,15 +57,26 @@ class Pandoc(str):
conv_from, conv_from,
'+'.join(self.in_options) '+'.join(self.in_options)
) )
is_pandoc_version2 = False
try:
version = subprocess.check_output(['pandoc', '-v'])
if version.startswith(b'pandoc 2'):
is_pandoc_version2 = True
except OSError:
print("Error: pandoc is not installed!")
cmd = [ cmd = [
'pandoc', 'pandoc',
'-o-', '-o-',
conv_to, conv_to,
conv_from, conv_from,
'--quiet',
'--no-highlight' '--no-highlight'
] ]
if is_pandoc_version2:
# Only pandoc v2 and higher support quiet param
cmd.append('--quiet')
if self.columns: if self.columns:
cmd.append(self.columns) cmd.append(self.columns)