docpad subdirectory rendered into general directory - docpad

How to move files from src/documents/posts/post1.html to out/post1.html without the subfolder posts appearing in the out directory?
I have a sub directory posts in my documents
src/
documents/
index.html
contact.html
posts/
post1.html
post2.html
And I want the posts to be in out/post1.html not out/posts/post1.html.

Turns out you can set the relativePath property to whatever you want
#getCollection("html").findAllLive(..).on 'add', (document) ->
newRelativePath = document.get('relativePath').replace('posts/','')
document.set('relativePath', newRelativePath)
ImportantNote:
if you use a findAllLive whith a selector that includes the relativePath and then change the relativePath, the document will be removed from the collection. Alternatively you can set another flag and use it for finding.
#getCollection("html").findAllLive({$or:{relativeOutDirPath:'posts', isPost: true}}).on 'add', (document) ->
document.set('relativePath', newRelativePath)
.setMeta({isPost: true})

Related

How to be able to find folders whose name keeps changing in shell/bash?

So I'm looking for a way for my shell to find the folder with the code behind the folder name that keeps changing, in the data/app/ folder, for example the folder "com.tencent.ig-yHGLSvh42dYO-GNMFS9WxA==". Which always changes only in the part after "com.tencent.ig-", the second "-" and "==". Full path "data/app/com.tencent.ig-yHGLSvh42dYO-GNMFS9WxA==/"
Code that can find the location of a folder so I can change the contents of that folder. If possible the code is contained in a variable so I can use it like so:
findfolder = (Code)؜
؜printf $findfolder

For Gazelle, how can I drop src from the generated importpath?

Because of the GoPath convention, I have all the code under src directory in my repo. Hence, the generated BUILD.bazel files have src appended to the importpaths. But imports to the go code from within the repo need to not have src in them. Hence, I have to update the generated importpath each time I add a new go directory.
I believe the support for go-prefix is on its way out. So I don't want to use that.
I can always update the importpath and add a #keep at the end to prevent subsequent updates. But, I was wondering if there was a way of controlling the generated importpath.
You can set the import path prefix in a subtree by adding a comment like this (replacing example.com/repo with whatever you want) to the build file in that subtree:
# gazelle:prefix example.com/repo
In your repo, you can set an empty prefix in the src directory. So in src/BUILD.bazel, add this comment:
# gazelle:prefix

smarty relative links with in html templates?

how do we include style sheets from a template file in smarty?
ca we use a relative path or does it have to be n absolute path?
structure might look like
project
|-- library
|-- css
|-- style.css
|--template
|--index.tpl
|--template_c
in the index.tpl what would be the proper format to access style.css?
would it ../library/css/style.css? or
/project/library/css/style.css?
It depends on what you want to do.
If your goal is to have the browser access the css file, you need to specify the path relative to the document root. so, if your project lies within htdocs, it might be /project/library/css/style.css.
If your goal is to read the CSS within Smarty (say to inline it) you need to specify the absolute file path (e.g. /home/users/foo/project/library/css/style.css)
Accessing files relative to the current template file works with ./file and ../file - but only for {include} and {extends}. Everything else must either be absolute or relative to the CWD (current working directory) of the actually executed script.

How to automatically find files of a specified type in the current directory or any specified sub-folders in Ruby?

I am using the following code to convert files from php to html. In order for it to work, I have to enter the name of each file on the second line.
p "convert files"
%w(file1 file2 file3).each do |name|
system %(php #{DIR}/#{name}.php > #{DIR2}/#{name}.htm)
end
Can someone tell me how to make it so it will automatically find any .php files in the main directory and look in any defined folder and their sub-folders for additional .php and save them in similar folder names?
For example:
file1.php -> file1.htm
about-us/file2.php -> about-us/file2.htm
contact-us/department/file3.php -> contact-us/department/file3.htm
The easiest way is to use Dir:
Dir.chdir('where_the_php_files_area')
Dir['**/*.php'].each do |php|
htm = 'where_the_html_files_should_go/' + php.sub(/\.php$/, '.htm')
system("php #{php} > #{htm}")
end
The ** pattern for Dir.glob (AKA Dir[]) matches directories recursively so Dir[**/*.php] will give you all the PHP files under the current directory.

How do I write an Albacore zip task that includes only certain folders and the folders themselves?

I'm trying to zip up the artifacts of a rake build, using Albacore's ZipTask. The solution I'm building has three projects that have artifacts that need to be zipped up individually, but only the ASP.NET MVC project will be mentioned here. Here's the directory structure of the solution:
rakefile.rb
solution.sln
src/
(other projects that are not relevant)
website/
(various folders I don't want included in the artifacts)
bin/
Content/
Scripts/
Views/
Default.aspx
Global.asax
web.config
At first I wrote this task:
website_directory = File.join '.', 'src', 'website'
website_project_name = 'website'
zip :zip => [ :run_unit_tests, :less ] do |zip|
zip.directories_to_zip = [ 'bin', 'Content', 'Scripts', 'Views' ].map{ |folder| File.join website_directory, folder }
zip.additional_files = [ 'Default.aspx', 'favicon.ico', 'Global.asax', 'web.config'].map{ |file| File.join website_directory, file }
zip.output_file = get_output_file_name
zip.output_path = get_artifacts_output_path website_project_name
end
Problem is, the output of this task is a zip file containing the contents of those folders, not the folders themselves, which is obviously undesirable.
Next, I tried flipping the flatten_zip field to false (which is not a documented field but you can find it in the source). This produced a zip that contained the above folders, but at the bottom of the whole ./src/website/ folder hierarchy. I want the above folders at the root of the zip, so that's not working either.
So my next shot was this, using exclusions, which is also not documented:
zip :zip => [ :run_unit_tests, :less ] do |zip|
zip.directories_to_zip website_directory
zip.exclusions = [ /.git/, /.+\.cs/, /App_Data/, /Attributes/, /AutoMapper/, /Controllers/, /Diagrams/, /Extensions/, /Filters/, /Helpers/, /Models/, /obj/, /Properties/, /StructureMap/, /Templates/, /CompTracker.Web.csproj/, /Default.aspx.cs/, /Global.asax.cs/, /Publish.xml/, /pdb/ ]
zip.output_file = get_output_file_name
zip.output_path = get_artifacts_output_path website_project_name
end
This worked for me, but when I recently added /AutoMapper/ and /StructureMap/ to the exclusions array, it also caused AutoMapper.dll and StructureMap.dll to (of course) also be excluded from the bin folder.
How should I edit any of the above tasks to have only the folders and files I want at the root of my zip?
You can copy all the files and folders you need into a temp directory and then zip that up. In other words, set the property directories_to_zip to one folder which has all the correct files already copied in - where the copying code is what does all the filtering for you. I think that's the unspecified expected usage (and the way I use it). I'll just contrast the two ideas to make it clear.
Strategy A: Copy the folder structure
Copy what you need into a temp directory. This way, you set the 'directories_to_zip' property to one folder eg:
directories_to_zip = 'ziptemp/all.my.stuff.copied.here/'
Strategy B: Use a filter
(This is your current strategy)
Use the directories_to_zip property as a filter on an original directory (it is an array that takes multiple directories, so you couldn't be blamed for assuming it should work this way). You then use various properties to filter the files/folders you need.
Possible Resolution
To solve your issue, then, you could adopt Strategy A. Actually, unless there's any extraordinary issues with this (slow PC, amazingly low on disk space), I would have thought this would be a slightly more robust way of going about it because you can be sure that what you are zipping is exactly what you are copying, which can be verified by checking the ziptemp directory.
Incidentally, I can be sure Strategy A works because I use it (with Albacore) to zip files for our installers.
I had the same problem using 'albacore', I wanted to zip a folder called 'tools' (not just the contents), store it in a folder called 'out' and name the zip 'tools.zip ... so instead I used this;
require 'zip/zipfilesystem'
Zip::ZipFile::open("out/tools.zip", Zip::ZipFile::CREATE) { |z|
Dir['{tools}/**/*'].each { |f|
z.add(f, f)
}
}
I know its late but I hope this helps someone.

Resources