How to get collections from sub-folder in docpad? - docpad

my folds structure are something like this:
documents
techs
docs
I want to get a collection from docs, my code is :
techs: ->
#getCollection("html").findAllLive({relativeOutDirPath: /techs/docs/},[{date: -1}]).on "add", (model) ->
model.setMetaDefaults({layout: "post"})
It just won't works... Could somebody tell me what's going on?

The /techs/docs/ in {relativeOutDirPath: /techs/docs/} is parsed as a regular expression, rather than a string. Wrap it in quotes so you have {relativeOutDirPath: "/techs/docs/"} instead. You may or may not need the initial slash, I can't remember.

You may want to use the convenient helper provided by Docpad : getFilesAtPath.

Maybe you should read the file "docpad.coffee"
There is a section "collection", you can set collection named "html", and select all files in (database).

I've had problems depending on what system I'm running node.js and docpad on (ie Windows) with file path conventions. So I resort to the following to make sure I'm not having any of those sort of problems:
#getCollection("html").findAllLive({relativeOutDirPath:path.join('techs','docs')},[date:-1])
Note the 'path.join' bit

Just as example, all html documents from path starts with "post"
#getCollection("html").findAllLive({relativeOutDirPath: {$beginsWith: 'post'}})

Related

Find Files in Folder - Search Query Includes Parentheses

I have a flow that pulls a list of filenames from an Excel file and then looks for them in a folder. Sometimes the filenames have parentheses in them, which causes issues with the search query and it doesn't even look for the file. I'm not sure how to handle the parentheses, but I don't want to remove the parentheses from the filenames (and ergo the search query). I thought about trimming the parentheses from the search query, but I want to make sure the right file is found. Perhaps I just need a way to escape the parentheses? I'm not sure how to do that though.
Here's a picture of the flow section in question:
I tried to find another post on this but after searching for a while I couldn't find anything, so I'm sorry if this has been answered already!
Any help is appreciated!
Edit: I'm going to try replacing any parentheses found with %28/%29 per Expiscornovus' suggestion.
Can you use a different search mode in the settings of your Find Files in Folder action (OneDriveSearch instead of Pattern)?
Ignore my previous suggested encoding. Inputting the Search query with parentheses should work. Look at the example below.

How can I find the content between multiple parameter strings (E.G. /contact-group/{ID}/member/{CONTACT-ID})

I had searched around but couldn't find something for it specifically. I was looking for a way to find the content of a URL (In this case these are URIs in a rest API)
A few examples of these look like:
/currency/{currency-id}
Or
/contact-group/{ID}/member/{CONTACT-ID}
The parameters always can be different, however they always are between {}, in different forms within the string. I know how I can replace these when there is only one in the URI without issue, but at runtime the programmer won't know these, and I'm trying to prevent having to define them and because of this when URIs contain multiple parameters I'm not sure how to obtain each case of them.
Happy for any ideas on how to get around this!
Seems like you're looking for a basic example of routing:
# in config/routes.rb
get "/:param_1/:param_2", to: "MyController#some_action"
Then in the controller you'd be able to get params[:param_1] and such.
You can see Rails' routing guide for more info
Maybe I'm not totally understanding your question, though. If you're looking to be able to capture a variable number of params, there's a special syntax for passing arrays in the query param.
See this: Passing array of parameters through get in rails
The answer to this was here
Basically using parameterset = url.scan(/{.+?}/) (replace url with your string name), and what's in scan with your parameter list, I can use this to do
parameterset.each { |x| x.... etc}

howto get Builder to create <tag></tag> instead of <tag/>

I,m using Builder::XmlMarkup to create xml. I want to create a tag without content because the api force me to create this.
If I use a blog
xml.tag do
end
I get what i need
<tag></tag>
but I want it shorter
xml.mytag
this gives me
<mytag/>
but i want
<mytag></mytag>
what do I have to pass as option.
regards Kai
Just pass empty string as a parameter. xml.mytag('')
Why do you want <mytag></mytag> instead of <mytag/>? Since the output is XML, downstream applications should not know or care about the difference.
According to the Infoset spec (Appendix D point 7), "The difference between the two forms of an empty element: <foo/> and <foo></foo>" is not represented in the XML Information Set.
This doesn't answer your "how" question, but if you discover that you actually don't need to do what you're trying to do, it may save you from a difficult and unnecessary wild goose chase.
ok empty string is nice, another one-line-way is empty block I found out.
xml.mytag{}

Using Apache and mod_ext_filter, need to dynamically replace values of static file based off of query string

I've got a situation where I need to alter the contents of a cached file based off of one of the query string arguments passed in. I'd love to use sed to do a simple regular expression replacement of a value based off of said argument but I can't figure that one out. I could use a ruby script to do the replacement for me but can't seem to access the query string for the request within the script. The documents for mod_ext_filter say:
In addition to the standard CGI environment variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set for the program.
Um yeah, can't seem to access those.
Has anybody any experience with this or does anybody have a better solution?
Doh! Looks like I simply need to access the ENV variable within ruby. Pretty dumb of me.
Using PHP scripting language server function we can able to get the query string values.
echo $_SERVER['REQUEST_URI'];
And pass the URL arguments as a variable to the file and make it dynamic.
Refer : PHP.net

In MVC, should pagination info go in the path or querystring?

In the path:
Format: http://mydomain.com/{category}/{subcategory}/{pageNumber}/{pageSize}
Example: http://mydomain.com/books/thriller/3/25
In the querystring:
Format: http://mydomain.com/{category}/{subcategory}? pageNumber={pageNumber}&pageSize={pageSize}
Example: http://mydomain.com/books/thriller?pageNumber=3&pageSize=25
I like having everything on the path, but my problem with that is that while it is obvious (or at least somewhat obvious) what "books" and "thriller" are in first example, the "3" and "25" seem pretty arbitrary by contrast.
Is there a canonical method for determining what goes where in MVC, or is it really just up to the dev?
I prefer things like pagenumbers to be in the querystring variables. I think there's a difference in descriptiveness between
http://mydomain.com/books/thriller?pagesize=50&page=4
and
http://mydomain.com/books/thriller/50/4
The point (to me) of having clean url's is for them to be more descriptive and readable, and I find the first example to be just that.
One interesting point made byJohnRudolfLewis is:
One rule of thumb that I follow is
that if the argument is required,
consider using the path, if the
argument is optional, always use
querystring arguments.
One rule of thumb that I follow is that if the argument is required, consider using the path, if the argument is optional, always use querystring arguments.
Overall, I'd stick to whatever makes the url look more readable.
This site puts it in the querystring: https://stackoverflow.com/questions?page=2&pagesize=30
Well, it's obviously up to you. But, you're designing a RESTful interface that's supposed to be human readable. The querystring is much better in that regard. Otherwise you're looking at two numbers that could really be anything. And who's going to remember the order?
Is there a canonical method for determining what goes where in MVC, or is it really just up to the dev?
It's up to you.
MVC is about the organization/flow of your server-side code and seperating the view from the business layer, not so much about query parameters.
You could also consider the following
Format
http://mydomain.com/{category}/{subcategory}/page/{pageNumber}/results/{pageSize}
Example
http://mydomain.com/books/thriller/page/3/results/25
It is pretty much up to the dev. I would say put the pageSize in the URL.

Resources