简体   繁体   中英

Where should I add my own Markdown file in Vapor project?

I want to add my own Markdown file, a file named profile.md . However, I don't know where I should add the file in my Vapor project, which is developed in Xcode.

I tried adding it to Sources/ or just the root directory, but it cannot be searched by Bundle.main.url(forResource:) function, like:

guard let url = Bundle.main.url(forResource: "profile", withExtension: ".md") else { ... }

Also, I found that I already added it under Copy Bundle Resources tab.

In the normal app (for iOS and macOS), the function above works properly.

How can I add my own file to be used in Vapor project developed in Xcode?

This is a very basic example of loading the contents of a file from a custom location using Foundation rather than Vapor's template view loading mechanism, and returning it as a text response.

drop.get { req in
  let templateString = try String(contentsOfFile: drop.workDir + "Resources/profile.md")
  return templateString
}

I'm not sure exactly what you mean by "parse, and embed it into another template file" but you'd put that bit in between the lines above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM