4a90d30e1c17 default tip

Add basic support for static assets/media
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 28 Aug 2020 00:21:29 -0400
parents 49612dd94ae1
children (none)
branches/tags default tip
files d/base.py docs/04-faqs.markdown

Changes

--- a/d/base.py	Tue Jan 14 20:06:16 2020 -0500
+++ b/d/base.py	Fri Aug 28 00:21:29 2020 -0400
@@ -235,6 +235,13 @@
     for filename in os.listdir(resources):
         shutil.copyfile(j(resources, filename), j(destination, '_dmedia', filename))
 
+    static_source = j(source, 'static')
+    if os.path.isdir(static_source):
+        static_destination = j(destination, 'static')
+        if os.path.isdir(static_destination):
+            shutil.rmtree(static_destination)
+        shutil.copytree(static_source, static_destination)
+
     chapters = []
     for filename in _find_chapters(source):
         chapter_title = _render(title, CONTENT_PRE, footer,
--- a/docs/04-faqs.markdown	Tue Jan 14 20:06:16 2020 -0500
+++ b/docs/04-faqs.markdown	Fri Aug 28 00:21:29 2020 -0400
@@ -98,9 +98,19 @@
 Sure.  Remember that Markdown lets you add raw HTML anywhere.  Just put the HTML
 in `footer.markdown` and you're all set.
 
-### Can I add media?
+### Can I add static assets/media?
+
+Yes, if there's a directory named `static` in your documentation source
+directory it will be copied into the output.
 
-Not yet, but it's on my radar.
+For example, you could have `static/foo.png` in your documentation directory and
+then put the following into your Markdown:
+
+    ![A picture of the elusive Foo](../static/foo.png)
+
+If you want to linkify the image, Just Use Markdown™:
+
+    [![A picture of the elusive Foo](../static/foo.png)](../static/foo.png)
 
 ### Can I display a table of contents for a single page?