Skip to content

Commit

Permalink
Merge branch 'feature/2018-08-07-file-structure'
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed Aug 30, 2018
2 parents f92f69f + 5741ed2 commit 1ad8b40
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 114 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For detailed information check [Blogophon's releases on Github](https://github.c
* :bomb: Change Geo-JSON properties to match JSON-Feed, add `atom:update` to RSS & JSON-RSS, fix date format in feeds
* :bomb: Replace `_language` in JSON feed with more general `_rss`
* :bomb: Replace proprietary date properties in JSON-RSS with Atom-properties and change JSON-RSS to have proper XMLNS
* :bomb: Switching Markdown file structure from `post/TITLE.md` to `post/TITLE/index.md` (see documentation on [how to move articles into new structure](advanced-stuff.md))
* :pill: Fix `browserconfig.xml` and the way configuration is handled
* :pill: Fix timezone for ICS files
* :gift: Add tracking pixel to newsfeeds, with `%url` and `%title` as replacements
Expand Down
18 changes: 18 additions & 0 deletions docs/advanced-stuff.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ If you use [Microsoft Visual Studio Code](https://code.visualstudio.com/) you ca

If you use [Github Atom](https://atom.io/) you can toggle the built-in Markdown preview by pressing `Ctrl + Shift + M`.

Migrating to new article structure
----------------------------------

In case you want to move articles from the old file structure (`user/posts/TITLE.md`) to the new file structure (`user/posts/TITLE/index.md`) here is a little bash script which will do this for all articles which already have an existing folder to move to:

```bash
#!/bin/bash

# Exectute in `user/posts`
for DIRECTORY in `find . -type d`; do
OLD_FILE="$DIRECTORY.md"
NEW_FILE="$DIRECTORY/index.md"
if [ -f $OLD_FILE ]; then
mv $OLD_FILE $NEW_FILE
fi
done
```

Server setup
------------

Expand Down
1 change: 1 addition & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ You do not have to use `blogophon` to generate your blog. All operations can be
## Create a new article

1. Create a new Markdown file in `user/posts`, e.g. `user/posts/TITLE.md`. The file name `TITLE` will be used as URL slug for your published article.
Alternatively put your new article in `user/posts/TITLE/index.md`. The directory name `TITLE` will be used as URL slug for your published article. This pattern is helpful if you plan on adding images to your article, as your images will be in the same directory as your article.
1. Edit your new files (see below).

## Edit existing markdown files
Expand Down
10 changes: 9 additions & 1 deletion docs/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ Attachments

Attachment files are files you want to use for your article. These files may be images, audio and video files, or any other type of document you can think of.

Put attachment files for your articles into a folder having the same name as the corresponding Markdown file without the file suffix `.md`:
Put attachment files into the same directory as your article:

```
/user/posts/example/index.md # Markdown file
/user/posts/example/image.jpg # Attachment file folder with example image
/user/posts/example/example.pdf # Attachment file folder with example PDF document
```

If you are using the old method of creating Markdown files, put attachments into a folder having the same name as the corresponding Markdown file without the file suffix `.md`:

```
/user/posts/example.md # Markdown file
Expand Down
82 changes: 25 additions & 57 deletions lib/blogophon-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ const BlogophonConsole = function() {
return choices;
};

internal.makePost = function(markdownFilename, filename, templateData) {
blogophonEditor.makePost(
/**
* [makePost description]
* @param {String} markdownFilename [description]
* @param {String} templateData [description]
* @return {[type]} [description]
*/
internal.makePost = function(markdownFilename, templateData) {
blogophonEditor.createFile(
markdownFilename,
filename,
templateData,
function(err) {
if (err) {
Expand Down Expand Up @@ -331,7 +336,6 @@ const BlogophonConsole = function() {
classes: 'Normal article',
link: '',
location: '',
images: false,
tags: function(answers) {
switch (answers.classes) {
case 'Micro post':
Expand Down Expand Up @@ -371,7 +375,7 @@ const BlogophonConsole = function() {
case 'Recipe':
return "Ingredients\n----------\n\n* Ingredient\n* Ingredient\n\nInstructions\n----------\n\n1. Instruction\n2. Instruction";
default:
return (answers.images ? '![](image.jpg#default)\n\n' : '') + 'Lorem ipsum…';
return '![](image.jpg#default)\n\nLorem ipsum…';
}
}
};
Expand Down Expand Up @@ -440,14 +444,6 @@ const BlogophonConsole = function() {
filter: function(v) {
return Number(v);
}
}, {
type: 'confirm',
name: 'images',
message: 'Do you want to attach files (e.g. images)?',
default: defaults.images,
when: function(answers) {
return (answers.classes !== 'Images' && answers.classes !== 'Micro post');
}
}, {
type: 'checkbox',
name: 'tags',
Expand Down Expand Up @@ -546,8 +542,9 @@ const BlogophonConsole = function() {
function(answers) {
answers.title = answers.title || Math.round(new Date().getTime() / 1000);
answers.date = blogophonDateFormat(answers.date, 'iso') || defaults.date;
let markdownFilename = blogophonEditor.filenameFromTitle(blogophonEditor.titleForFilename(answers.title, config, answers.date)) + '.md';
let filename = blogophonEditor.dirnameFromFilename(markdownFilename); // TODO: There is a class for that
let markdownFilename = blogophonEditor.filenameFromTitle(
blogophonEditor.titleForFilename(answers.title, config, answers.date)
);
let templateData = answers;
templateData.isMicropost = (answers.classes === 'Micro post');
templateData.lead = templateData.lead || defaults.lead(answers);
Expand All @@ -566,10 +563,10 @@ const BlogophonConsole = function() {
blogophonEditor.convertAddress(templateData.location, config.locale.language, function(err, geo) {
templateData.latitude = geo.latitude || templateData.latitude;
templateData.longitude = geo.longitude || templateData.longitude;
internal.makePost(markdownFilename, filename, templateData);
internal.makePost(markdownFilename, templateData);
});
} else {
internal.makePost(markdownFilename, filename, templateData);
internal.makePost(markdownFilename, templateData);
}

},
Expand Down Expand Up @@ -615,7 +612,7 @@ const BlogophonConsole = function() {
{
type: 'list',
name: 'file',
message: 'Select filen to rename ('+files.length+')',
message: 'Select file to rename ('+files.length+')',
choices: files
}, {
type: 'input',
Expand All @@ -625,42 +622,20 @@ const BlogophonConsole = function() {
return blogophonEditor.shortfilenameFromTitle(v);
},
validate: function(v) {
return v.match(/\.md~?$/) ? true : 'Please supply a file ending like `.md` or `.md~`.';
return !v.match(/\.md~?$/) ? true : 'Please omit file ending like `.md` or `.md~`.';
}
}
];
inquirer.prompt(questions).then(
function(answers) {
if (answers.fileNew) {
let processed = 0, maxProcessed = 2;
let checkProcessed = function(err) {
blogophonEditor.renameFile(answers.file, answers.fileNew, (err) => {
if (err) {
console.error(err);
}
if (++processed === maxProcessed) {
console.log(answers.file + " files moved to "+answers.fileNew+", you may want to generate & publish all index pages");
external.init();
}
};

fs.move(
config.directories.data + '/' + answers.file,
config.directories.data + '/' + answers.fileNew,
checkProcessed
);
fs.move(
config.directories.data + '/' + blogophonEditor.dirnameFromFilename(answers.file),
config.directories.data + '/' + blogophonEditor.dirnameFromFilename(answers.fileNew),
checkProcessed
);
if (! answers.file.match(/~$/)) {
maxProcessed ++;
fs.move(
config.directories.data.replace(/^user/, 'htdocs') + '/' + blogophonEditor.dirnameFromFilename(answers.file),
config.directories.data.replace(/^user/, 'htdocs') + '/' + blogophonEditor.dirnameFromFilename(answers.fileNew),
checkProcessed
);
}
console.log(answers.file + " files moved to "+answers.fileNew+", you may want to generate & publish all index pages");
external.init();
});
} else {
external.init();
}
Expand Down Expand Up @@ -691,21 +666,14 @@ const BlogophonConsole = function() {
];
inquirer.prompt(questions).then(
function(answers) {
if (answers.sure) {
let processed = 0, maxProcessed = 3;
let checkProcessed = function(err) {
if (answers.sure && answers.file) {
blogophonEditor.deleteFile(answers.file, (err) => {
if (err) {
console.error(err);
}
if (++processed === maxProcessed) {
console.log(answers.file + " files deleted, you may want to generate & publish all index pages");
external.init();
}
};

fs.remove(path.join(config.directories.data, answers.file), checkProcessed);
fs.remove(path.join(config.directories.data, blogophonEditor.dirnameFromFilename(answers.file)), checkProcessed);
fs.remove(path.join(config.directories.data.replace(/^user/, 'htdocs'), blogophonEditor.dirnameFromFilename(answers.file)), checkProcessed);
console.log("Files / directories deleted, you may want to generate & publish all index pages");
external.init();
});
} else {
external.init();
}
Expand Down
Loading

0 comments on commit 1ad8b40

Please sign in to comment.