Skip to content

Commit

Permalink
fix static file transfer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanta212 committed Jul 20, 2019
1 parent e2abc69 commit f1d742b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Blogger-cli
A custom cli tool to process jupyter notebooks, markdown files and html files. Write your blog in markdown or jupyter notebooks and then transform into blog post with mathjax, code support, google analytics, navigation, disqus support.

See a sample blog made by blogger-cli: [Here](https://pykancha.github.io/test/)

## Why?
It is easy to get your hands on, works flawlessly and won't get bulky and slow overtime.
Expand Down Expand Up @@ -56,6 +57,8 @@ Open the url http://localhost:8000/ in your browser to view your blog!!
- [Writing blog's metadata](docs/meta.md)
- [Recommended workflow for blogger-cli](docs/workflow.md)

> View docs in: [website](https://hemanta.github.io/blogger-cli/)
## Author

👤 **Hemanta Sharma**
Expand Down
2 changes: 1 addition & 1 deletion blogger_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

__version__ = '1.0.0a3'
__version__ = '1.0.1'
ROOT_DIR = os.path.join(os.path.split(__file__)[0])
RESOURCE_DIR = os.path.join(os.path.split(__file__)[0], 'resources')

Expand Down
33 changes: 25 additions & 8 deletions blogger_cli/converter/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,31 @@ def extract_and_write_static(ctx, html_body, topic_filename, blog_post_dir):


def extract_videos(ctx, videos, video_path, filename, blog_post_dir):
for index, video_tag in enumerate(videos):
def get_name_from_title(video_tag):
try:
video_name = video_tag['title'].strip().lower()
except:
video_name = None
return video_name


def get_video_data(video_tag):
try:
video_data = video_tag['src']
except:
video_data = video_tag.source['src']
return video_data



for index, video_tag in enumerate(videos):
try:
video_name = video_tag['title'].strip().lower()
video_data = get_video_data(video_tag)
except:
video_name = None
ctx.log("Cannot find src attribute. Skipping...")
continue

video_name = get_name_from_title(video_tag)

if not video_name:
video_name = 'video_' + str(index+1)
Expand All @@ -68,7 +83,8 @@ def extract_videos(ctx, videos, video_path, filename, blog_post_dir):
dest_path = os.path.dirname(video_path)
extracted_path = extract_static_files(video_data, file_path, dest_path)
if extracted_path:
new_video_src = get_static_src(blog_post_dir, video_path)
ctx.log(":: Detected STATIC video. Copying to", extracted_path)
new_video_src = get_static_src(blog_post_dir, extracted_path)
video_tag['src'] = new_video_src


Expand Down Expand Up @@ -101,6 +117,7 @@ def extract_images(ctx, images, img_path, filename, blog_post_dir):
dest_path = os.path.dirname(image_path)
extracted_path = extract_static_files(img_data, file_path, dest_path)
if extracted_path:
ctx.log(":: Detected STATIC img. Copying to", extracted_path)
new_img_src = get_static_src(blog_post_dir, extracted_path)
img_tag['src'] = new_img_src

Expand Down Expand Up @@ -153,14 +170,14 @@ def get_absolute_path(ctx, filename):
return file_path[0]


def extract_static_files(data, file_path, dest_dir):
def extract_static_files(file_name, file_path, dest_dir):
orig_dir = Path(os.path.dirname(file_path))
static_path = orig_dir / data
data = os.path.basename(data)
static_path = orig_dir / file_name
file_name = os.path.basename(file_name) # manage cases like ../../video.mp4

if static_path.exists():
static_path = static_path.resolve()
dest_path = os.path.join(dest_dir, data)
dest_path = os.path.join(dest_dir, file_name)
shutil.copyfile(str(static_path), dest_path)
return dest_path

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[tool.poetry]
name = "blogger-cli"
version = "1.0.0"
version = "1.0.1"
description = "Blogger cli is a CLI tool to convert ipynb, md, txt file to responsive html files."
authors = ["hemanta212 <sharmahemanta.212@gmail.com>"]
readme = "README.md"
repository = "https://github.com/hemanta212/blogger-cli"
documentation = "https://hemanta212.github.io/blogger-cli"
keywords = ["jupyter notebook", "github pages", "blogger"]
license = "MIT"

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

setup(
name='blogger-cli',
version = "1.0.0a3",
version = "1.0.1",
description = "Blogger cli is a CLI tool to convert ipynb, md, txt file to responsive html files.",
authors = ["hemanta212 <sharmahemanta.212@gmail.com>"],
readme = 'README.md',
repository = "https://github.com/hemanta212/blogger-cli",
documentation = "https://hemanta212.github.io/blogger-cli",
keywords = ["jupyter notebook", "github pages", "blogger"],
license = "MIT",

packages=['blogger_cli', 'blogger_cli.commands', 'blogger_cli.cli_utils',
'blogger_cli.blog_manager', 'blogger_cli.converter'],
include_package_data=True,
install_requires=[
'click', 'nbconvert', 'markdown'
'click', 'nbconvert', 'markdown', 'bs4'
],
entry_points='''
[console_scripts]
Expand Down

0 comments on commit f1d742b

Please sign in to comment.