Add local markdown files to GraphQL layer in Gridsome - gridsome

In Gridsome, how do you add local markdown files to the GraphQL layer, so that you can add graphql to vue components?
At the time of writing, the Gridsome docs for adding data from local files are empty.

The starter-blog also has a working implementation: https://github.com/gridsome/gridsome-starter-blog/blob/master/gridsome.config.js
The gridsome repo for source-filesystem has some docs to help: https://github.com/gridsome/gridsome/tree/master/packages/source-filesystem
Docs imported here in case the link breaks in the future (but the link is likely to be more up to date).
#gridsome/source-filesystem
Transform files into content that can be fetched with GraphQL in your components.
Install
yarn add #gridsome/source-filesystem
npm install #gridsome/source-filesystem
Usage
module.exports = {
plugins: [
{
use: '#gridsome/source-filesystem',
options: {
path: 'blog/**/*.md',
typeName: 'BlogPost',
route: '/blog/:year/:month/:day/:slug'
}
}
]
}
A filesystem source will also require a transformer in order to parse the files. The example above is looking for a set of Markdown files, so in order to let Gridsome understand the content of the files, you must install #gridsome/transformer-remark as a dev dependency in your project. Gridsome will automatically transform the files for you as long as a transformer that supports your files is found in your package.json.
Options
path
Type: string required
Where to look for files. Should be a glob path.
typeName
Type: string
Default: 'FileNode'
The GraphQL type and template name. A .vue file in src/templates must match the typeName to have a template for it.
route
Type: string
Define a dynamic route if your source is able to have a certain pathname structure. This will generate a single route for all nodes from this source. Possible path params are year, month, day, slug or any custom field value. If omitted, a route for each file will be generated based on their path and filename. Read more about route params.
refs
Type: object
Define fields that will have a reference to another node. The referenced typeName is expected to exist. But a content type can also be created autmatically if you set create: true. Read more about references.
{
refs: {
// Reference to existing authors by id.
author: 'Author',
// Create a Tag content type and its nodes automatically.
tags: {
typeName: 'Tag',
route: '/tag/:id',
create: true
}
}
}
index
Type: Array
Default: ['index']
Define which files to consider as index files. These files will not have their filename appear in its route path and will become the main index.html file of the directory. Make sure there is only one possible index file per directory if multiple index names are defined.

Related

Creating a link in linux from root by means of a puppet manifest

Good afternoon, I need to create a link in the /usr/share/applications/desktop Astra Linux directory from the root user. With the name of the link, the path where it leads and the shortcut. How can this be implemented by puppet manifest? I read the documentation and tried, but nothing came out :(.
class automount_oep_mount_disk_x {
# preferred symlink syn
file { '/usr/share/applications/flydesktop':
ensure => 'file',
name +> 'desktop',
}
Whatever documentation you read must not have been the official Puppet Resource Type Reference. Very near the top of the docs for the File resource type, you will find
The file type can manage normal files, directories, and symlinks; the type should be specified in the ensure attribute.
(Emphasis added)
The docs for the ensure attribute that that references say, in part:
Possible values are present, absent, file, directory, and link. [...]
link ensures the file is a symlink, and requires that you also set the target attribute.
(Emphasis in the original)
As its name suggests, the target attribute designates the target of the symlink (I'll spare you yet another excerpt from the docs).
Overall, then, it will look something like this ...
file { '/usr/share/applications/flydesktop':
ensure => 'link',
target => # you didn't appear say
# possibly other attributes, too ...
}
Of course, this describes only the form of the specific manifest code
for managing the symlink. The rest of the details of creating classes, classifying nodes, and building and applying catalogs are too many and too diverse for one SO answer.

How to filter and get folder with latest date in google dataflow

I am passing in an wilcard match string as gs://dev-test/dev_decisions-2018-11-13*/. And i am passing to TextIO as below.
p.apply(TextIO.read().from(options.getLocalDate()))
Now i want to read all folders from the bucket named dev-test and filter and only read files from the latest folder. Each folder has a name with timestamp appended to it.
I am new to dataflow and not sure how would I go about doing this.
Looking at the JavaDoc here it seems as though we can code:
String folder = // The GS path to the latest/desired folder.
PCollection<String> myPcollection = p.apply(TextIO.Read.from(folder+"/*")
The resulting PCollection will thus contain all the text lines from all the files in the specified folder.
Assuming you can have multiple folders in the same bucket with the same date prefix/suffix as for example "data-2018-12-18_part1", "data-2018-12-18_part2" etc, the following will work. Its a python example but it works for Java as well. You will just need to get the date formatted as per your folder name and construct the path accordingly.
# defining the input path pattern
input = 'gs://MYBUCKET/data-' + datetime.datetime.today().strftime('%Y-%m-%d') + '*\*'
(p
| 'ReadFile' >> beam.io.ReadFromText(input)
...
...
it will read all the files from all the folders matching the pattern
If you know that the most recent folder will always be today's date, you could use a literal string as in Tanveer's answer. If you don't know that and need to filter the actual folder names for the most recent date, I think you'll need to use FileIO.match to read file and directory names, and then collect them all to one node in order to do figure out which is the most recent folder, then pass that folder name into TextIO.read().from().
The filtering might look something like:
ReduceByKey.of(FileIO.match("mypath"))
.keyBy(e -> 1) // constant key to get everything to one node
.valueBy(e -> e)
.reduceBy(s -> ???) // your code for finding the newest folder goes here
.windowBy(new GlobalWindows())
.triggeredBy(AfterWatermark.pastEndOfWindow())
.discardingFiredPanes()
.output()

Symfony2: How to create own translation files?

I want to create my own translation file. For Example I want a "my-application.en_EN.yml" in my tranlsations folder in Ressources in my Bundle.
When I do this, the translation in my file does not work.
Only when I name the file like the standard name "messages.en_EN.yml" then it works.
But how can I have my own namings?
messages.{language}.yml is the default name of translation files (in YML format), Symfony will load the translation file automatically and provide translations in all the contexts.
It's different if the translation file has a different name, in this case you have to add the first part of the file name (the translation domain) as an argument when translating a string:
In a Controller:
$this->get('translator')->trans('my.message', array(), 'my-application');
In a Twig template:
{{ 'my.message'|trans({}, 'my-application') }}
See the official documentation for further information:
Translations (The Symfony Book)
The Translation Component (The Symfony Components)

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

Is there a way to modify the entity mapping configuration for doctrine outside the config file?

In my standard Symfony2-app I'm having a bunch of bundles with some entities. Some of these entities are not located in the standard folder the automapping of doctrine finds out (e.g. /src/Acme/DemoBundle/Entities) but in a different location.
I could easily use config.yml to tell doctrine to use a different location like this:
doctrine:
orm:
auto_mapping: false
mappings:
AcmeDemoBundle:
type: annotation
prefix: Acme\DemoBundle\Entities\
dir: %kernel.cache_dir%\Acme\DemoBundle\Entities
This works. But say I'm having 10 bundles with a different mapping the config.yml gets bloated very fast. Is there another way, e.g. with a CompilerPass or via DependencyInjection, so I don't need to add all entities in my config.yml? I already looked into the DoctrineBundle, but had no luck so far.
To answer myself:
the most simple way is to adjust the autoloading, there is no need to modify the settings. In Symfony's standard distribution in autoload.php you have to add another location to the registerNamespace-method:
$loader->registerNamespaces(array(
[...]
'Foo' => array(__DIR__.'/../src/dirA', __DIR__.'/../src/dirB')
));
Doctrine will then look for entities in the "Foo" namespace first in dirA and then in dirB if not found.
You can include other configuration files using imports
# yaml
imports:
- { resource: entities.yml }
<!-- xml -->
<imports>
<import resource="enditites.xml" />
</imports>
// PHP
$loader->import('entities.php');
You don't even have to stick to a single file type. It's possible to import an xml configuration file to a yaml file, for example.

Resources