I am looking for a way to ensure that upon build a PDF will end up in a specific directory. I am using the jekyll-pages-directory plugin to create the structure of this site. Not looking to embed the PDF in a page, not trying to link to it from my assets folder. Need it to have a URL of that places it within a specific path without redirects.
When I place the PDF into the directory inside of the pages folder I get errors from Jekyll about it not being a valid byte sequence. I assume that this means Jekyll doesn't know how to handle the file type. The Error is as follows:
Error reading file /Users/path/to/site/_pages/path/to/my.pdf: invalid byte sequence in UTF-8
Liquid Exception: invalid byte sequence in UTF-8 in path/to/my.pdf
jekyll 2.5.3 | Error: invalid byte sequence in UTF-8
So in short how can I make Jekyll place my PDF into the correct directory in _site upon build so that I can control what its url would be?
Related
I am building a web app and I would like to show PDF files to my users. My files are mainly stored as byte arrays in the database as they are generated in the backend. I am using the embed element and have found three ways to display a PDF:
Local file path in src attribute: Works, but I need to generate a file from the database byte array, which is not desirable as I have to manage routines to delete them once they are not needed anymore.
Online file path in src attribute: Not possible since my files may not be hosted anywhere but on the server. Also has the same issues as the previous method anyway.
Data as base64 string in src attribute: Current method, but I ran into a problem for larger files (>2MB). Edge and Chrome will not display a PDF when I covert a PDF of this size to a base64 string (no error but the docs reveal that there is a limit for the data in the src attribute). It works on Firefox but I cannot have my users be restricted to Firefox.
Is there any other way to transmit valid PDF data from a byte array out of the database without generating a file locally?
You have made the common mistake of thinking of URLs and file paths as the same thing; but a URL is just a string that's sent to the server, and some content is sent back. Just as you wouldn't save an HTML file to disk for every dynamic page on the site, you don't have to write to the file system to display a dynamic PDF.
So the solution to this is to have a script on your server that takes the identifier of a PDF in your system, maybe does some access checking, and outputs it to the browser.
For example, if you were using PHP, you might write the HTML with <embed src="/loadpdf.php?id=42"> and then in loadpdf.php would write something like this:
$pdfContent = load_pdf_from_database((int)$_GET['id']);
header('Content-Type: application/pdf');
echo $pdfContent;
Loading /loadpdf.php?id=42 directly in the browser would then render the PDF just the same as if it was a "real" file, and embedding it should work the same way too.
I've inherited a process that converts markdown content into html using jekyll.
If I remove the yaml front matter between ---, by client request to simplify the process for editors,
---
product: Product Name
capability: testing
infotype: Overview
audience:
---
# Testing file 2
This is another testing file.
The jekyll build doesn't convert the file.
# Testing file 2
This is another testing file.
When I have the front matter in the testing 2 file I see the following in the log when running build --verbose
Rendering: user-administration/testing-file-2.md
Pre-Render Hooks: user-administration/testing-file-2.md
Rendering Markup: user-administration/testing-file-2.md
Rendering Layout: user-administration/testing-file-2.md
but without the front matter there is no message in the log related to testing-file-2.md
This testing-file-2.md is part of a collection of other files that have metadata. They are render into an html website but not the testing-file-2.md when the metadata is removed.
Is there a way for jekyll to build and render files without front matter?
Jekyll does not ignore any files. Rather, for each file, it decides whether the file is:
a static file, which can be copied as-is to the output folder (_site), or
a file to be processed first.
Markdown files (.md) are processed by kramdown and Liquid if they start with YAML frontmatter:
---
---
otherwise they are treated as static files, and copied to _site with no processing.
There is a workaround that might work for you using include_relative; but it may cause more trouble for your client's editors than it's worth, depending how they work.
You can include a static file inside a file to be processed. Your static file might be plain-text.md:
# Static text file
This is a file with no YAML frontmatter.
Then, separately, you create a markdown file with frontmatter that will include the plain-text file inside it. Say, processed-text.md:
---
---
{% include_relative plaintext.md %}
Then your plain text will be processed and appear on your site as /processed-text. Think of the file processed-text.md as a kind of template for holding plain-text.md.
You'll want to see the docs on include_relative, especially the fact that the file to be included can't be above the including file in the file system.
I've read that it's a requirement to have at minimum at empty front matter or jekyll will ignore the file
---
---
Short story: I want to be able to store non-text files/directories in the _posts/ folder.
This is not about local assets, or anything like that. I literally just want to store files (non-associated images and directories) there for a specific, unrelated issue that doesn't merit discussion.
Is there a way to put a folder in _posts/ and in essence have Jekyll ignore all of its contents? Or at least, not freak out about the contents being non-text files?
EDIT: It seems that the actual errors are coming from the names of some of the sub-subdirectories. When the name of these directories start with a date, it gives me the error:
Liquid Exception: invalid byte sequence in UTF-8 in /Users/burchill/burchill.github.io/_posts/blah/source/2017-10-28-blahblah_post/blah.png
EDIT #2: After changing the directory names to "play nice" with Jekyll's regex, Jekyll no longer gives an error, but when I try to link to these images on my posts, they don't show up, unlike files in other non-_posts directories.
Jekyll won't process files not starting with the triple dashes block (frontmatter) so it is safe to have any other file in your _posts folder.
https://jekyllrb.com/docs/frontmatter/
I'm trying to use the MediaWiki filepath magic word` so that I can create some template links that pass a specific MediaWiki file. Unfortunately with certain file types, filepath just returns nothing.
The file I'm trying to get the path for that's failing is a text file in this case. I have confirmed that I am using the correct filename as I can create a regular file link using [[File:Name.txt]], and {{filepath:Image.png}} works properly.
Example of what I'm trying to accomplish:
[http://server/processfile.php?path={{filepath:<filename>}} Process A File]
Is this a known issue? Is there an easy way that I can debug what's happening here?
After digging around a bunch more I was able to resolve the issue. It turns out that even though the MediaWiki would accept the file, it was being assigned a random mime type because it was a .yaml file.
After updating mime.types and mime.info in MediaWiki and adding the mime type (text/yaml) to my IIS configuration, I was able to get the downloads working and the file links showing up.
Full disclosure: I may have been using an incorrectly cased file name even though I said that I was using the correct file name. :P
I have a few HTML files that I'd like to include via tags in my webapp.
Within some of the files, I have pseudo-dynamic code - specially formatted bits of text that, at runtime, I'd like to be resolved to their respective bits of data in a MySQL table.
For instance, the HTML file might include a line that says:
Welcome, [username].
I want this resolved to (via a logged-in user's data):
Welcome, user#domain.com.
This would be simple to do in a JSP file, but requirements dictate that the files will be created by people who know basic HTML, but not JSP. Simple text-tags like this should be easy enough for me to explain to them, however.
I have the code set up to do resolutions like that for strings, but can anyone think of a way to do it across files? I don't actually need to modify the file on disk - just load the content, modify it, and output it w/in the containing JSP file.
I've been playing around with trying to load the files into strings via the apache readFileToString, but I can't figure out how to load files from a specific folder within the webapp's content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.
but I can't figure out how to load files from a specific folder within the webapp's content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.
If those files are located in the webcontent, use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path. This works if the WAR is exploded in the appserver (most does it by default, only Weblogic doesn't do that by default, but this is configureable IIRC). Inside servlets you can obtain the ServletContext by the inherited getServletContext() method.
String relativeWebappURL = "/html/file.html";
String absoluteFilePath = getServletContext().getRealPath(relativeWebappURL);
File file = new File(absoluteFilePath);
// ...
Alternatively, you can put it in the classpath of the webapplication and make use of ClassLoader#getResource():
String relativeClasspathURL = "/html/file.html";
URL absoluteClasspathURL = Thread.currentThread().getContextClassLoader().getResource(relativeClasspathURL);
File file = new File(absoluteClasspathURL.toURI());
// ...
As to the complete picture, I question if you have ever considered an existing templating framework like Freemarker or Velocity to ease all the job?